activemodel-csv_validator 0.1.2 → 0.4.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: 54fb95b435cca7028c60d4d3b5f504b505c9aa7f319186b67c046cc0f73dd661
4
- data.tar.gz: 2db441729fcd5d45534ebdfe64de47ad7cfb0f8faeff08d61af1263e9470d0c3
3
+ metadata.gz: 8fd12e527341af3f693fe8e8212c684751c8e45fcb4de9d3069ee3a482df0445
4
+ data.tar.gz: 8533c6126319e1a956c9f5f4d9e84e00ad6e991e884ceca6b2d6a65c5d1f845a
5
5
  SHA512:
6
- metadata.gz: 88c3e60bf3797839d34f2f4aa65973c0d9df66a73b76988b55988899063bd4a4a452f82c1f589bfee8e78e643f87a344af6367e38bc9a68df2de9c050a39e4dc
7
- data.tar.gz: b222343748c62a20e7dbcf3fbc1b3ee240de25420270b054cdab3315583448b0ad5a55111a325299e380ab85c0edccf768637b811cde17fd2deebaff51f78456
6
+ metadata.gz: f10ad1fb87c9378e8dcadbd46e85207073345871fed953793e53a4ed20ef1d0d0a8e687a86c23fcad8ddb25fd4a68d11e9f8ef2bce87d2aea90e374dfbbf1b52
7
+ data.tar.gz: ccd3dafafbdff4fed38a0fa6ff09fb9d3c68d8d8c1fa197a1636f12dba017f72d351b58b8d18ae0955681f9c503fcb038e22514791ed6c3200a103834e09ffd9
@@ -0,0 +1,22 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby: ["2.7", "3.0", "3.1", ruby-head, jruby-head]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ bundler-cache: true # 'bundle install' and cache gems
20
+ ruby-version: ${{ matrix.ruby }}
21
+ - name: Run tests
22
+ run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 0.4.0
2
+
3
+ - Drop support ruby@2.6
4
+ - Drop support rails@6.0
5
+ - Proc can now be passed to `headers` option.
6
+
7
+ ## 0.2.0
8
+
9
+ - Drop support ruby@2.5
10
+ - Fix keyword args warn
11
+
1
12
  ## 0.1.2
2
13
 
3
14
  - Update dependency
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,8 +22,9 @@ 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.add_dependency "activemodel", ">= 5.2.0"
26
- spec.add_dependency "activesupport", ">= 5.2.0"
25
+ spec.required_ruby_version = '>= 2.7.0'
26
+ spec.add_dependency "activemodel", ">= 6.1.0"
27
+ spec.add_dependency "activesupport", ">= 6.1.0"
27
28
  spec.add_development_dependency "bundler", "~> 2.0"
28
29
  spec.add_development_dependency "rake", "~> 13.0"
29
30
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -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.2'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -12,11 +12,16 @@ module ActiveModel
12
12
  rows = CSV.parse(content, headers: :first_row, converters: :integer)
13
13
 
14
14
  if options[:max].present? && rows.size > options[:max]
15
- 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))
16
20
  end
17
21
 
18
22
  if options[:headers].present?
19
- missing_headers = options[:headers] - rows.headers
23
+ headers = options[:headers].respond_to?(:call) ? options[:headers].call(record) : options[:headers]
24
+ missing_headers = headers - rows.headers
20
25
  if missing_headers.present?
21
26
  record.errors.add(attribute, :missing_headers, missing_headers: missing_headers.to_sentence)
22
27
  end
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.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-22 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.0
19
+ version: 6.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.0
26
+ version: 6.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 5.2.0
33
+ version: 6.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 5.2.0
40
+ version: 6.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -87,9 +87,9 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/workflows/ci.yml"
90
91
  - ".gitignore"
91
92
  - ".rspec"
92
- - ".travis.yml"
93
93
  - CHANGELOG.md
94
94
  - CODE_OF_CONDUCT.md
95
95
  - Gemfile
@@ -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.7.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/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.3
7
- before_install: gem install bundler -v 2.0.2