activemodel-csv_validator 0.2.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: 70497b097149f6420e459692ce751284d875f4fffefb300effaaf0bc968bb0af
4
- data.tar.gz: c90873d6905072f64ab9ac0ec9e4d14bb48ce466767eeaaed4cc28373602eccc
3
+ metadata.gz: cb70efb8db9417e97271234408c30226f68d3762f6bead02ad62d32a35ab3174
4
+ data.tar.gz: a0f5e957d47de6f6a267df40cfeb43c42b95a68026ec66912d40aaf714babdee
5
5
  SHA512:
6
- metadata.gz: 42860cc23cec314965afe22f391b5b8e16236493a7879f22199e3d9c9907c5ca2d72bbc4c2e0ba4b7bada981ba1a4005a83f7424e9cfdbdf900151ef7f9f762b
7
- data.tar.gz: 2e6d01b41a9698946e6ad19928a660262929274ede445c8e5e04ab576ea485e72e371baf17fa47936e737c915497a6e2e7f7fb25578c27688033801dfe0361c1
6
+ metadata.gz: d3082350fdb33f663589223f7de9530bdb39d0195d5da153ec014c552cb437227330aed4324080021fb7c90363590b48dbdf1bcdb9b39e5f927d9fdeb58657db
7
+ data.tar.gz: 7adad3526afda27bb99ef778bfb779c6abd58b477d76c2f078c9df5199dc8f3706eafa801f88326476e7cce2686d04467fdcc71db87545cb099f621b17e8145b
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
 
@@ -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.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -15,6 +15,10 @@ module ActiveModel
15
15
  record.errors.add(attribute, :max_rows, **options.slice(:max).merge(rows: rows.size))
16
16
  end
17
17
 
18
+ if options[:min].present? && rows.size < options[:min]
19
+ record.errors.add(attribute, :min_rows, **options.slice(:min).merge(rows: rows.size))
20
+ end
21
+
18
22
  if options[:headers].present?
19
23
  missing_headers = options[:headers] - rows.headers
20
24
  if missing_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.2.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: 2021-07-17 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