rails_importer 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +9 -0
- data/app/controllers/rails_importer/imports_controller.rb +7 -4
- data/app/views/rails_importer/imports/new.html.erb +3 -0
- data/config/locales/rails_importer.en.yml +2 -0
- data/config/locales/rails_importer.es.yml +2 -0
- data/config/routes.rb +5 -1
- data/lib/rails_importer/base.rb +6 -1
- data/lib/rails_importer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 960482940d9658460f988cc0ebb40b48ae004205
|
4
|
+
data.tar.gz: 6633a7b469898d1450be8189729a3763ae4db22d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c0591bd134f1e8dbde0179f701ea07ebbbce4ef6978f292d789509e05ac6a0bcc09de3e14f2f7585ae5ba441702ba1984e69edb20ae486e205498e65f0797a0
|
7
|
+
data.tar.gz: 3e5c4469e487e6c5384f948d1583a8ac86f9154a33393655021957a20745f5f0eae0da799043b0bb359a20302fe460e6291392044e724f91765bbbcdfcea73f9
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -112,6 +112,15 @@ end
|
|
112
112
|
```
|
113
113
|
The `context` variable used above contains the app routes, so don't forget to use it.
|
114
114
|
|
115
|
+
## Sample files
|
116
|
+
You can add a sample file for each importer if you wish to communicate the spreadsheet structure your importer follows.
|
117
|
+
|
118
|
+
The sample file must be located inside the `lib/rails_importer/templates/` folder and have the same name as your importer key. For the `ExampleImporter` used above, the path would be: `lib/rails_importer/templates/example.xslx`
|
119
|
+
|
120
|
+
The import form has a link to the sample file. If you do not declare the file, then this link will redirect to `after_import_path`.
|
121
|
+
|
122
|
+
Note: `.xlsx` sample files are the only ones currently supported (for now).
|
123
|
+
|
115
124
|
## Import Job
|
116
125
|
When processing an import file, an ActiveJob instance is used. If you're deploying to production, you will want to use some active job adapter, such as [Sidekiq](https://github.com/mperham/sidekiq).
|
117
126
|
|
@@ -17,11 +17,14 @@ module RailsImporter
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
def sample
|
21
|
+
file = File.open(@importer_class.sample_file)
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
send_data file.read, :filename => File.basename(@importer_class.sample_file)
|
24
|
+
rescue => e
|
25
|
+
flash[:alert] = I18n.t(:sample_file_not_available, scope: :rails_importer)
|
26
|
+
redirect_to after_import_path
|
27
|
+
end
|
25
28
|
|
26
29
|
private
|
27
30
|
|
@@ -2,3 +2,5 @@ es:
|
|
2
2
|
rails_importer:
|
3
3
|
importer_does_not_exist: El importador especificado no existe
|
4
4
|
processing_import: La importación ha comenzado. En unos instances el resultado estará disponible.
|
5
|
+
sample_file: Archivo de ejemplo
|
6
|
+
sample_file_not_available: Archivo de ejemplo no disponible
|
data/config/routes.rb
CHANGED
data/lib/rails_importer/base.rb
CHANGED
@@ -56,9 +56,14 @@ module RailsImporter
|
|
56
56
|
raise "#{__FILE__}:#{__LINE__} You must define it"
|
57
57
|
end
|
58
58
|
|
59
|
+
# The importer sample file
|
60
|
+
def self.sample_file
|
61
|
+
Rails.root.join("lib/rails_importer/templates/#{key}.xlsx")
|
62
|
+
end
|
63
|
+
|
59
64
|
private
|
60
65
|
|
61
|
-
# Returns a Roo instance
|
66
|
+
# Returns a Roo::Spreadsheet instance according the file extension.
|
62
67
|
def open_spreadsheet sheet_name = ''
|
63
68
|
extension = File.extname(@filepath.split("/").last)
|
64
69
|
@spreadsheet = Roo::Spreadsheet.open(@filepath, extension: extension)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastián Vicencio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|