valigator-csv 1.4.1 → 1.5.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
  SHA1:
3
- metadata.gz: 321282981d2382b5a94723e6784996baa9983cd9
4
- data.tar.gz: 1fc69c450f9622d1ded2912d9407e6b0482a6d93
3
+ metadata.gz: 54ed9fc641ce391e995b63f06a2fec44fbf2da4d
4
+ data.tar.gz: 021f08c2fa878dff7dc28a400fee15f6bc1ffcb8
5
5
  SHA512:
6
- metadata.gz: 247bf7242477c4e65b3299221857b8128af1cdd65bfcbb6dbd933381912d66e66114cd899dff25f7b0af6a3b010dd8a40b02fc46cc4d58b1da8b41316aff74a7
7
- data.tar.gz: 0e8a6720b8f9a34d08441cf22f09c6c3039be600766df71bdf1061141d842c161fcb316a1a21fe70b8281e965bce525d8cc5cf916c7855b6a7682455cb52ff3e
6
+ metadata.gz: 106c81bb41c7655e704c2b5e2bbe5fab0c4f4f89625357344684b19188570769c773bf328bb492af6f89e8aa544665410e2bf0a39f0232553e7f0d52970e2bb3
7
+ data.tar.gz: b6a4ad060dfb70029a02f20fedb0dfd91f76891dba26d9c5dc4a28359391a419ba2c916faebb2dbd144a16fa28600673af6b23a8dc0b43399604f6542c8b25cc
@@ -10,7 +10,7 @@ module Valigator
10
10
 
11
11
  class Error
12
12
 
13
- attr_reader :row, :type, :message, :field
13
+ attr_reader :row, :type, :message, :field, :details
14
14
 
15
15
 
16
16
 
@@ -26,7 +26,7 @@ module Valigator
26
26
 
27
27
 
28
28
  def ==(other)
29
- row == other.row && message == other.message && type == other.type && field == other.field
29
+ row == other.row && message == other.message && type == other.type && field == other.field && details == other.details
30
30
  end
31
31
 
32
32
 
@@ -36,7 +36,8 @@ module Valigator
36
36
  row: row,
37
37
  type: type,
38
38
  message: message,
39
- field: field
39
+ field: field,
40
+ details: details
40
41
  }
41
42
  end
42
43
 
@@ -45,7 +46,7 @@ module Valigator
45
46
  private
46
47
 
47
48
  def build_from_hash(error)
48
- build error[:type], error[:message], error[:row], error[:field]
49
+ build error[:type], error[:message], error[:row], error[:field], error[:details]
49
50
  end
50
51
 
51
52
 
@@ -63,11 +64,12 @@ module Valigator
63
64
 
64
65
 
65
66
 
66
- def build(type, message, row, field=nil)
67
+ def build(type, message, row, field = nil, details = nil)
67
68
  @type = type
68
69
  @row = row
69
70
  @message = message
70
71
  @field = field
72
+ @details = details
71
73
  end
72
74
 
73
75
 
@@ -55,7 +55,7 @@ module Valigator
55
55
 
56
56
 
57
57
  def unrelated_error?(error)
58
- error.is_a?(ArgumentError) && error.message != 'invalid byte sequence in UTF-8'
58
+ error.is_a?(ArgumentError) && error.message !~ /invalid byte sequence in/
59
59
  end
60
60
 
61
61
 
@@ -67,7 +67,7 @@ module Valigator
67
67
  validator = options[:field_validators][field]
68
68
 
69
69
  if validator && !validator.valid?(row[index])
70
- add_error_for(validator, field)
70
+ add_error_for(validator, field, row)
71
71
  end
72
72
  end
73
73
  end
@@ -94,17 +94,25 @@ module Valigator
94
94
  end
95
95
  end
96
96
 
97
+ def add_error_for(validator, field = nil, row = nil)
98
+ error_hash = error_hash(validator, field)
99
+ error_hash.merge!({details: error_details(row)}) if error_details(row)
97
100
 
101
+ errors << CSV::Error.new(error_hash)
102
+ end
98
103
 
99
- def add_error_for(validator, field = nil)
100
- errors << CSV::Error.new({
104
+ def error_hash(validator, field = nil)
105
+ {
101
106
  type: validator.error_type,
102
107
  message: validator.error_message,
103
108
  row: $INPUT_LINE_NUMBER,
104
109
  field: field
105
- })
110
+ }
106
111
  end
107
112
 
113
+ def error_details(row)
114
+ config[:details].call(row) if config.has_key?(:details)
115
+ end
108
116
  end
109
117
  end
110
118
  end
@@ -1,5 +1,5 @@
1
1
  module Valigator
2
2
  module CSV
3
- VERSION = "1.4.1"
3
+ VERSION = "1.5.0"
4
4
  end
5
5
  end
@@ -6,8 +6,8 @@ require 'valigator/csv/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'valigator-csv'
8
8
  spec.version = Valigator::CSV::VERSION
9
- spec.authors = ['Daniel Nagy', 'Istvan Demeter', 'Tamas Drahos']
10
- spec.email = ['naitodai@gmail.com', 'demeter.istvan@gmail.com', 'drahostamas@gmail.com']
9
+ spec.authors = ['Daniel Nagy', 'Istvan Demeter', 'Tamas Drahos', 'Milan Unicsovics']
10
+ spec.email = ['naitodai@gmail.com', 'demeter.istvan@gmail.com', 'drahostamas@gmail.com', 'u.milan@gmail.com']
11
11
 
12
12
  spec.summary = %q{Yet another CSV validator library}
13
13
  spec.description = %q{Yet another CSV validator library. Just better.}
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valigator-csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Nagy
8
8
  - Istvan Demeter
9
9
  - Tamas Drahos
10
+ - Milan Unicsovics
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2015-12-23 00:00:00.000000000 Z
14
+ date: 2017-05-10 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: bundler
@@ -59,6 +60,7 @@ email:
59
60
  - naitodai@gmail.com
60
61
  - demeter.istvan@gmail.com
61
62
  - drahostamas@gmail.com
63
+ - u.milan@gmail.com
62
64
  executables: []
63
65
  extensions: []
64
66
  extra_rdoc_files: []