activemodel-csv_validator 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6e9cb06ee2d9328efdd099140042880c6de947675f8fbc3dc185b23d5e00e5c
4
- data.tar.gz: 7f0b66a5ab3c7d84bb23fe6df2067418597da25a2aad708d816862b0a4d72bcf
3
+ metadata.gz: cb70efb8db9417e97271234408c30226f68d3762f6bead02ad62d32a35ab3174
4
+ data.tar.gz: a0f5e957d47de6f6a267df40cfeb43c42b95a68026ec66912d40aaf714babdee
5
5
  SHA512:
6
- metadata.gz: d1a04a5fef137d27977093a4059a83dec3cf750ca3844fd925e40a9d6991b43e1519be0179681b25c791c88e6816b7a601637bb29528b3377fef120aa24fa2af
7
- data.tar.gz: ab5c1f9e00c10631ed418428b95ac1f6e758f4821e7898554c2403c7c4fd1a00fe79972c66c95cd8600f8678615b9b38b7027d69253dbaf04ed58d450268d98e
6
+ metadata.gz: d3082350fdb33f663589223f7de9530bdb39d0195d5da153ec014c552cb437227330aed4324080021fb7c90363590b48dbdf1bcdb9b39e5f927d9fdeb58657db
7
+ data.tar.gz: 7adad3526afda27bb99ef778bfb779c6abd58b477d76c2f078c9df5199dc8f3706eafa801f88326476e7cce2686d04467fdcc71db87545cb099f621b17e8145b
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## 0.2.0
2
+
3
+ - Drop support ruby@2.5
4
+ - Fix keyword args warn
5
+
6
+ ## 0.1.2
7
+
8
+ - Update dependency
9
+
10
+ ## 0.1.0
11
+
12
+ - First Release
data/README.md CHANGED
@@ -26,7 +26,7 @@ class CsvForm
26
26
 
27
27
  attr_accessor :file
28
28
 
29
- validates :file, presence: true, csv: { max: 100, headers: %w[field1 field2 field3] }
29
+ validates :file, presence: true, csv: { min: 1, max: 100, headers: %w[field1 field2 field3] }
30
30
  end
31
31
  ```
32
32
 
@@ -22,9 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
+ spec.required_ruby_version = '>= 2.6.0'
25
26
  spec.add_dependency "activemodel", ">= 5.2.0"
26
27
  spec.add_dependency "activesupport", ">= 5.2.0"
27
28
  spec.add_development_dependency "bundler", "~> 2.0"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rake", "~> 13.0"
29
30
  spec.add_development_dependency "rspec", "~> 3.0"
30
31
  end
@@ -3,5 +3,6 @@ en:
3
3
  errors:
4
4
  messages:
5
5
  invalid_csv: "is not a valid CSV file"
6
+ min_rows: "should have more than %{max} rows"
6
7
  max_rows: "should have no more than %{max} rows"
7
8
  missing_headers: "should have %{missing_headers} columns"
@@ -3,5 +3,6 @@ ja:
3
3
  errors:
4
4
  messages:
5
5
  invalid_csv: "のフォーマットが正しくありません。"
6
+ min_rows: "のデータが%{rows}件あります。%{min}件以上にしてください。"
6
7
  max_rows: "のデータが%{rows}件あります。%{max}件以下にしてください。"
7
8
  missing_headers: "には%{missing_headers}のフィールドが不足しています。"
@@ -1,5 +1,5 @@
1
1
  module Activemodel
2
2
  module CsvValidator
3
- VERSION = "0.1.0"
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -6,11 +6,17 @@ module ActiveModel
6
6
  module Validations
7
7
  class CsvValidator < ActiveModel::EachValidator
8
8
  def validate_each(record, attribute, value)
9
+ return if value.nil?
10
+
9
11
  content = NKF.nkf('-w', File.read(value.path, universal_newline: true))
10
12
  rows = CSV.parse(content, headers: :first_row, converters: :integer)
11
13
 
12
14
  if options[:max].present? && rows.size > options[:max]
13
- record.errors.add(attribute, :max_rows, options.slice(:max).merge(rows: rows.size))
15
+ record.errors.add(attribute, :max_rows, **options.slice(:max).merge(rows: rows.size))
16
+ end
17
+
18
+ if options[:min].present? && rows.size < options[:min]
19
+ record.errors.add(attribute, :min_rows, **options.slice(:min).merge(rows: rows.size))
14
20
  end
15
21
 
16
22
  if options[:headers].present?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel-csv_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -90,9 +90,9 @@ files:
90
90
  - ".gitignore"
91
91
  - ".rspec"
92
92
  - ".travis.yml"
93
+ - CHANGELOG.md
93
94
  - CODE_OF_CONDUCT.md
94
95
  - Gemfile
95
- - Gemfile.lock
96
96
  - LICENSE.txt
97
97
  - README.md
98
98
  - Rakefile
@@ -116,14 +116,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: '0'
119
+ version: 2.6.0
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 3.0.3
126
+ rubygems_version: 3.1.2
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: CSV Validator for Active Model
data/Gemfile.lock DELETED
@@ -1,53 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- activemodel-csv_validator (0.1.0)
5
- activemodel (>= 5.2.0)
6
- activesupport (>= 5.2.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (6.0.1)
12
- activesupport (= 6.0.1)
13
- activesupport (6.0.1)
14
- concurrent-ruby (~> 1.0, >= 1.0.2)
15
- i18n (>= 0.7, < 2)
16
- minitest (~> 5.1)
17
- tzinfo (~> 1.1)
18
- zeitwerk (~> 2.2)
19
- concurrent-ruby (1.1.5)
20
- diff-lcs (1.3)
21
- i18n (1.7.0)
22
- concurrent-ruby (~> 1.0)
23
- minitest (5.13.0)
24
- rake (10.5.0)
25
- rspec (3.9.0)
26
- rspec-core (~> 3.9.0)
27
- rspec-expectations (~> 3.9.0)
28
- rspec-mocks (~> 3.9.0)
29
- rspec-core (3.9.0)
30
- rspec-support (~> 3.9.0)
31
- rspec-expectations (3.9.0)
32
- diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.9.0)
34
- rspec-mocks (3.9.0)
35
- diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.9.0)
37
- rspec-support (3.9.0)
38
- thread_safe (0.3.6)
39
- tzinfo (1.2.5)
40
- thread_safe (~> 0.1)
41
- zeitwerk (2.2.1)
42
-
43
- PLATFORMS
44
- ruby
45
-
46
- DEPENDENCIES
47
- activemodel-csv_validator!
48
- bundler (~> 2.0)
49
- rake (~> 10.0)
50
- rspec (~> 3.0)
51
-
52
- BUNDLED WITH
53
- 2.0.2