rails_spreadsheet_reader 0.1.3 → 0.1.4
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 +8 -8
- data/lib/rails_spreadsheet_reader/base.rb +19 -4
- data/lib/rails_spreadsheet_reader/version.rb +2 -2
- data/spec/base_spec.rb +1 -1
- metadata +1 -3
- data/spec/files/users_duplicated.csv +0 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTllZmRmOTIyYzY2OTRhMjRlMTM2NGNhODYyOWNlMDk3NmRiNWY4Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjQwOGJlNmE2ZGZhMWE1NTc2NTEzNDIyNTI2YzUwNGQ5Mjg1ZDEzYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTdjNWQ1MjU1MTQzZTczNjVhNDdlZjdlZmU5NzA2ODc4ODYyZjgzZTFjMDU2
|
10
|
+
ZjRjN2Q5NTFkNWU4MjJjMDQ5NWM1MjBmMTNkNzRiY2IzZjliOGI5NjBjNmNm
|
11
|
+
NWIxZDgwM2ZmNjE0NDA3NGQ0NWZjYzkwNGJkNzAwM2Q2MDJlMjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDYwMTdmZDc1MmY2YWE4ZDczZGQ3ZDgxZjBhMzg2YzI4MzIwZTVhNDU3NGU3
|
14
|
+
M2U0ZGE1MDFmNmMzY2ZkOWRmYzdlYTgxODVlYzUzNjQzN2VmMzk5M2JhY2Vh
|
15
|
+
Yzk4OTQwMmM1Zjk1NTY3ZGY2ODYyM2ZiMTdkNjVhZTY0MDMzMTM=
|
@@ -13,13 +13,28 @@ module RailsSpreadsheetReader
|
|
13
13
|
|
14
14
|
attr_accessor :row_number
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
attr_accessor :models_with_errors
|
17
|
+
|
18
|
+
# Errors should be copied in a validation callback because valid?
|
19
|
+
# method flushes errors.
|
20
|
+
validate :copy_errors_on_validation
|
21
|
+
|
22
|
+
def copy_errors_on_validation
|
23
|
+
self.models_with_errors ||= []
|
24
|
+
self.models_with_errors.each do |model|
|
25
|
+
model.errors.full_messages.each do |msg|
|
26
|
+
errors.add(:base, msg)
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
31
|
+
# Models are added models_with_errors. They will be copied in to self.errors on
|
32
|
+
# copy_errors_on_validation callback
|
33
|
+
def copy_errors(model)
|
34
|
+
self.models_with_errors ||= []
|
35
|
+
self.models_with_errors << model
|
36
|
+
end
|
37
|
+
|
23
38
|
# Defines the starting row of the excel where the class should start reading the data.
|
24
39
|
#
|
25
40
|
# == Returns:
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module RailsSpreadsheetReader
|
2
|
-
VERSION = '0.1.
|
3
|
-
end
|
2
|
+
VERSION = '0.1.4'
|
3
|
+
end
|
data/spec/base_spec.rb
CHANGED
@@ -78,7 +78,7 @@ describe RailsSpreadsheetReader::Base do
|
|
78
78
|
user_spreadsheet.errors.add(:username, 'is unique')
|
79
79
|
expect(user_spreadsheet.valid?).to eq(false)
|
80
80
|
expect(user_spreadsheet.invalid?).to eq(true)
|
81
|
-
valid =
|
81
|
+
valid = EmptyColumnSpreadsheet.new
|
82
82
|
valid.copy_errors(user_spreadsheet)
|
83
83
|
expect(valid.valid?).to eq(false)
|
84
84
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_spreadsheet_reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- muzk
|
@@ -115,7 +115,6 @@ files:
|
|
115
115
|
- rails_spreadsheet_reader.gemspec
|
116
116
|
- spec/base_spec.rb
|
117
117
|
- spec/files/users.csv
|
118
|
-
- spec/files/users_duplicated.csv
|
119
118
|
- spec/files/users_invalid.csv
|
120
119
|
- spec/models/empty_column_spreadsheet.rb
|
121
120
|
- spec/models/invalid_column_spreadsheet.rb
|
@@ -150,7 +149,6 @@ summary: Provides an easy way to add model-based validations to excel files.
|
|
150
149
|
test_files:
|
151
150
|
- spec/base_spec.rb
|
152
151
|
- spec/files/users.csv
|
153
|
-
- spec/files/users_duplicated.csv
|
154
152
|
- spec/files/users_invalid.csv
|
155
153
|
- spec/models/empty_column_spreadsheet.rb
|
156
154
|
- spec/models/invalid_column_spreadsheet.rb
|