[CloudoLife-RoR] col_active_importer_starter: A starter(or wrapper) to active_importer gem
col_active_importer_starter
col_active_importer_starter is a starter(or wrapper) to active_importer - https://github.com/continuum/active_importer gem.
Features
col_active_importer_starter
makes full use of active_importer
gem to import tabular data from spreadsheets or similar sources into Active Record models.
- The best practices of
active_importer
, such as: - Introduce a optional cache to retain data in the memory
- Write out a file with the original data and more information for result
Installation
Add this line to your application’s Gemfile:
1 | gem 'col_active_importer_starter' |
And then execute:
1 | bundle |
Or install it yourself as:
1 | gem install col_active_importer_starter |
Usages
Suppose there is a ActiveRecord model Article
:
1 | class Article < ApplicationRecord |
and tabular data file data/Articles.xlsx
Title | Body |
---|---|
Article.1.title | Article.1.body |
Article.2.title | Article.2.body |
- Create a
ArticleImporter
extendColActiveImporterStarter::BaseImporter
1 | # app/importers/article_import.rb |
- Import data from a file.
1 | ArticleImporter.execute("#{Rails.root}/data/Articles.1.xlsx") |
Or specify more arguments.
1 | params = { |
- Then, check
tmp/importers
directory to find the result file.
Title | Body | Result ID | Result Message | |
---|---|---|---|---|
Article.1.title | Article.1.body | 1 | success | |
Article.2.title | Article.2.body | 2 | success |
Inspire
Inspire by active_importer - https://github.com/continuum/active_importer.
Contributing
Contributions are welcome! Take a look at our contributions guide for details.
The basic workflow for contributing is the following:
- Fork it - https://github.com/CloudoLife/col_active_importer_starter/fork
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am ‘Add some feature’)
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
License
The gem is available as open source under the terms of the MIT License - https://opensource.org/licenses/MIT.
References
[1] [CloudoLife-RoR/col_active_importer_starter: col_active_importer_starter is a starter(or wrapper) to active_importer. - https://github.com/CloudoLife-RoR/col_active_importer_starter
[4] RubyGems.org | your community gem host - https://rubygems.org/