simple_params 1.6.9 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", ">= 5.1"
6
+ gem "shoulda-matchers", ">= 3.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ simple_params (2.0.3)
5
+ activemodel (>= 3.0, <= 7.0)
6
+ shoulda-matchers (>= 2.8)
7
+ virtus (>= 1.0.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (5.2.3)
13
+ activesupport (= 5.2.3)
14
+ activesupport (5.2.3)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ appraisal (2.2.0)
20
+ bundler
21
+ rake
22
+ thor (>= 0.14.0)
23
+ axiom-types (0.1.1)
24
+ descendants_tracker (~> 0.0.4)
25
+ ice_nine (~> 0.11.0)
26
+ thread_safe (~> 0.3, >= 0.3.1)
27
+ coderay (1.1.2)
28
+ coercible (1.0.0)
29
+ descendants_tracker (~> 0.0.1)
30
+ concurrent-ruby (1.1.4)
31
+ descendants_tracker (0.0.4)
32
+ thread_safe (~> 0.3, >= 0.3.1)
33
+ diff-lcs (1.3)
34
+ equalizer (0.0.11)
35
+ i18n (1.0.1)
36
+ concurrent-ruby (~> 1.0)
37
+ ice_nine (0.11.2)
38
+ method_source (0.9.2)
39
+ minitest (5.11.3)
40
+ pry (0.12.0)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.9.0)
43
+ rake (10.4.2)
44
+ rspec (2.99.0)
45
+ rspec-core (~> 2.99.0)
46
+ rspec-expectations (~> 2.99.0)
47
+ rspec-mocks (~> 2.99.0)
48
+ rspec-core (2.99.2)
49
+ rspec-expectations (2.99.2)
50
+ diff-lcs (>= 1.1.3, < 2.0)
51
+ rspec-mocks (2.99.3)
52
+ shoulda-matchers (3.1.2)
53
+ activesupport (>= 4.0.0)
54
+ thor (0.20.3)
55
+ thread_safe (0.3.6)
56
+ tzinfo (1.2.5)
57
+ thread_safe (~> 0.1)
58
+ virtus (1.0.5)
59
+ axiom-types (~> 0.1)
60
+ coercible (~> 1.0)
61
+ descendants_tracker (~> 0.0, >= 0.0.3)
62
+ equalizer (~> 0.0, >= 0.0.9)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ activemodel (>= 5.1)
69
+ appraisal
70
+ bundler (>= 1.5)
71
+ pry
72
+ rake (>= 10.1)
73
+ rspec (>= 2.6)
74
+ shoulda-matchers (>= 3.0)
75
+ simple_params!
76
+
77
+ BUNDLED WITH
78
+ 2.1.4
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", ">= 5.2"
6
+ gem "shoulda-matchers", ">= 3.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ simple_params (2.0.3)
5
+ activemodel (>= 3.0, <= 7.0)
6
+ shoulda-matchers (>= 2.8)
7
+ virtus (>= 1.0.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (5.2.3)
13
+ activesupport (= 5.2.3)
14
+ activesupport (5.2.3)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ appraisal (2.2.0)
20
+ bundler
21
+ rake
22
+ thor (>= 0.14.0)
23
+ axiom-types (0.1.1)
24
+ descendants_tracker (~> 0.0.4)
25
+ ice_nine (~> 0.11.0)
26
+ thread_safe (~> 0.3, >= 0.3.1)
27
+ coderay (1.1.2)
28
+ coercible (1.0.0)
29
+ descendants_tracker (~> 0.0.1)
30
+ concurrent-ruby (1.1.4)
31
+ descendants_tracker (0.0.4)
32
+ thread_safe (~> 0.3, >= 0.3.1)
33
+ diff-lcs (1.3)
34
+ equalizer (0.0.11)
35
+ i18n (1.0.1)
36
+ concurrent-ruby (~> 1.0)
37
+ ice_nine (0.11.2)
38
+ method_source (0.9.2)
39
+ minitest (5.11.3)
40
+ pry (0.12.0)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.9.0)
43
+ rake (10.4.2)
44
+ rspec (2.99.0)
45
+ rspec-core (~> 2.99.0)
46
+ rspec-expectations (~> 2.99.0)
47
+ rspec-mocks (~> 2.99.0)
48
+ rspec-core (2.99.2)
49
+ rspec-expectations (2.99.2)
50
+ diff-lcs (>= 1.1.3, < 2.0)
51
+ rspec-mocks (2.99.3)
52
+ shoulda-matchers (3.1.2)
53
+ activesupport (>= 4.0.0)
54
+ thor (0.20.3)
55
+ thread_safe (0.3.6)
56
+ tzinfo (1.2.5)
57
+ thread_safe (~> 0.1)
58
+ virtus (1.0.5)
59
+ axiom-types (~> 0.1)
60
+ coercible (~> 1.0)
61
+ descendants_tracker (~> 0.0, >= 0.0.3)
62
+ equalizer (~> 0.0, >= 0.0.9)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ activemodel (>= 5.2)
69
+ appraisal
70
+ bundler (>= 1.5)
71
+ pry
72
+ rake (>= 10.1)
73
+ rspec (>= 2.6)
74
+ shoulda-matchers (>= 3.0)
75
+ simple_params!
76
+
77
+ BUNDLED WITH
78
+ 2.1.4
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", ">= 6.0"
6
+ gem "shoulda-matchers", ">= 3.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ simple_params (2.0.3)
5
+ activemodel (>= 3.0, <= 7.0)
6
+ shoulda-matchers (>= 2.8)
7
+ virtus (>= 1.0.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (6.0.2.2)
13
+ activesupport (= 6.0.2.2)
14
+ activesupport (6.0.2.2)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ zeitwerk (~> 2.2)
20
+ appraisal (2.2.0)
21
+ bundler
22
+ rake
23
+ thor (>= 0.14.0)
24
+ axiom-types (0.1.1)
25
+ descendants_tracker (~> 0.0.4)
26
+ ice_nine (~> 0.11.0)
27
+ thread_safe (~> 0.3, >= 0.3.1)
28
+ coderay (1.1.2)
29
+ coercible (1.0.0)
30
+ descendants_tracker (~> 0.0.1)
31
+ concurrent-ruby (1.1.6)
32
+ descendants_tracker (0.0.4)
33
+ thread_safe (~> 0.3, >= 0.3.1)
34
+ diff-lcs (1.3)
35
+ equalizer (0.0.11)
36
+ i18n (1.8.3)
37
+ concurrent-ruby (~> 1.0)
38
+ ice_nine (0.11.2)
39
+ method_source (1.0.0)
40
+ minitest (5.14.1)
41
+ pry (0.13.0)
42
+ coderay (~> 1.1)
43
+ method_source (~> 1.0)
44
+ rake (13.0.1)
45
+ rspec (2.99.0)
46
+ rspec-core (~> 2.99.0)
47
+ rspec-expectations (~> 2.99.0)
48
+ rspec-mocks (~> 2.99.0)
49
+ rspec-core (2.99.2)
50
+ rspec-expectations (2.99.2)
51
+ diff-lcs (>= 1.1.3, < 2.0)
52
+ rspec-mocks (2.99.3)
53
+ shoulda-matchers (4.3.0)
54
+ activesupport (>= 4.2.0)
55
+ thor (1.0.1)
56
+ thread_safe (0.3.6)
57
+ tzinfo (1.2.7)
58
+ thread_safe (~> 0.1)
59
+ virtus (1.0.5)
60
+ axiom-types (~> 0.1)
61
+ coercible (~> 1.0)
62
+ descendants_tracker (~> 0.0, >= 0.0.3)
63
+ equalizer (~> 0.0, >= 0.0.9)
64
+ zeitwerk (2.3.0)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ activemodel (>= 6.0)
71
+ appraisal
72
+ bundler (>= 1.5)
73
+ pry
74
+ rake (>= 10.1)
75
+ rspec (>= 2.6)
76
+ shoulda-matchers (>= 3.0)
77
+ simple_params!
78
+
79
+ BUNDLED WITH
80
+ 2.1.4
@@ -6,7 +6,7 @@ module SimpleParams
6
6
 
7
7
  private
8
8
  def hash_to_symbolized_hash(hash)
9
- hash.inject({}){|result, (key, value)|
9
+ hash.to_h.inject({}){|result, (key, value)|
10
10
  new_key = case key
11
11
  when String then key.to_sym
12
12
  else key
@@ -15,7 +15,7 @@ module SimpleParams
15
15
  if nested_attribute?(attribute)
16
16
  set_nested(attribute)
17
17
  else
18
- get(attribute.to_sym) || set(attribute.to_sym, [])
18
+ super(attribute)
19
19
  end
20
20
  end
21
21
 
@@ -24,6 +24,7 @@ module SimpleParams
24
24
  end
25
25
 
26
26
  def add(attribute, message = :invalid, options = {})
27
+ message = message.call if message.respond_to?(:call)
27
28
  message = normalize_message(attribute, message, options)
28
29
  if exception = options[:strict]
29
30
  exception = ActiveModel::StrictValidationFailed if exception == true
@@ -42,7 +43,7 @@ module SimpleParams
42
43
  super &&
43
44
  nested_instances.all? { |i| i.errors.empty? }
44
45
  end
45
- alias_method :blank?, :empty?
46
+ alias_method :blank?, :empty?
46
47
 
47
48
  def include?(attribute)
48
49
  if nested_attribute?(attribute)
@@ -51,7 +52,7 @@ module SimpleParams
51
52
  messages[attribute].present?
52
53
  end
53
54
  end
54
- alias_method :has_key?, :include?
55
+ alias_method :has_key?, :include?
55
56
  alias_method :key?, :include?
56
57
 
57
58
  def values
@@ -61,18 +62,22 @@ module SimpleParams
61
62
 
62
63
  def full_messages
63
64
  parent_messages = map { |attribute, message| full_message(attribute, message) }
64
- nested_messages = nested_instances.map do |i|
65
+ nested_messages = nested_instances.map do |i|
65
66
  i.errors.full_messages.map { |message| "#{i.parent_attribute_name} " + message }
66
67
  end
67
68
 
68
69
  (parent_messages + nested_messages).flatten
69
70
  end
70
71
 
72
+ def to_a
73
+ full_messages
74
+ end
75
+
71
76
  def to_hash(full_messages = false)
72
77
  msgs = get_messages(self, full_messages)
73
78
 
74
79
  @nested_classes.map do |attribute, klass|
75
- nested_msgs = run_or_mapped_run(klass) do |k|
80
+ nested_msgs = run_or_mapped_run(klass) do |k|
76
81
  unless k.nil?
77
82
  get_messages(k.errors, full_messages)
78
83
  end
@@ -99,22 +104,22 @@ module SimpleParams
99
104
  @nested_classes.keys.include?(attribute.to_sym)
100
105
  end
101
106
 
102
-
103
- def add_error_to_attribute(attribute, error)
107
+ def add_error_to_attribute(attribute, message)
104
108
  if nested_attribute?(attribute)
105
- @nested_classes[attribute].errors.add(:base, error)
109
+ @nested_classes[attribute].errors.add(:base, message)
106
110
  else
107
- self[attribute] << error
111
+ self[attribute] << message
108
112
  end
109
113
  end
110
114
 
111
115
  def get_messages(object, full_messages = false)
116
+ valid_messages = object.messages.reject { |key, val| empty_messages?(val) }
112
117
  if full_messages
113
- object.messages.each_with_object({}) do |(attribute, array), messages|
118
+ valid_messages.each_with_object({}) do |(attribute, array), messages|
114
119
  messages[attribute] = array.map { |message| object.full_message(attribute, message) }
115
120
  end
116
121
  else
117
- object.messages.dup
122
+ valid_messages
118
123
  end
119
124
  end
120
125
 
@@ -137,7 +142,11 @@ module SimpleParams
137
142
  def set_nested(attribute)
138
143
  klass = nested_class(attribute)
139
144
  errors = run_or_mapped_run(klass) { |k| k.errors if k.present? }
140
- set(attribute.to_sym, errors)
145
+ if respond_to?(:normalize_detail)
146
+ detail = normalize_detail(errors, {})
147
+ details[attribute.to_sym] = detail
148
+ end
149
+ messages[attribute.to_sym] = errors
141
150
  end
142
151
 
143
152
  def nested_instances
@@ -21,7 +21,7 @@ module SimpleParams
21
21
  end
22
22
 
23
23
  def class_instances
24
- nested_class_hash.each_pair.inject([]) do |array, (key, value)|
24
+ nested_class_hash.each_pair.inject([]) do |array, (_key, value)|
25
25
  array << value
26
26
  array.flatten.compact
27
27
  end
@@ -18,7 +18,7 @@ module SimpleParams
18
18
  end
19
19
 
20
20
  def [](attribute)
21
- get(attribute.to_sym) || set(attribute.to_sym, [])
21
+ super(attribute)
22
22
  end
23
23
 
24
24
  def []=(attribute, error)
@@ -58,6 +58,10 @@ module SimpleParams
58
58
  map { |attribute, message| full_message(attribute, message) }
59
59
  end
60
60
 
61
+ def to_a
62
+ full_messages
63
+ end
64
+
61
65
  def to_hash(full_messages = false)
62
66
  get_messages(self, full_messages)
63
67
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleParams
2
- VERSION = "1.6.9"
2
+ VERSION = "2.0.4"
3
3
  end
@@ -4,25 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'simple_params/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "simple_params"
7
+ spec.name = 'simple_params'
8
8
  spec.version = SimpleParams::VERSION
9
- spec.authors = ["brycesenz"]
10
- spec.email = ["bryce.senz@gmail.com"]
9
+ spec.authors = ['brycesenz']
10
+ spec.email = ['bryce.senz@gmail.com']
11
11
  spec.description = %q{Simple way to specify API params}
12
12
  spec.summary = %q{A DSL for specifying params, including type coercion and validation}
13
- spec.homepage = "https://github.com/brycesenz/simple_params"
14
- spec.license = "MIT"
13
+ spec.homepage = 'https://github.com/brycesenz/simple_params'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "activemodel", ">= 3.0", "< 5.0"
22
- spec.add_dependency "virtus", ">= 1.0.0"
23
- spec.add_dependency "shoulda-matchers", "~> 2.8"
24
- spec.add_development_dependency "bundler", "~> 1.5"
25
- spec.add_development_dependency "rake", "~> 10.1"
26
- spec.add_development_dependency "rspec", "~> 2.6"
27
- spec.add_development_dependency "pry"
21
+ spec.add_dependency 'activemodel', '>= 3.0', '<= 7.0'
22
+ spec.add_dependency 'virtus', '>= 1.0.0'
23
+ spec.add_dependency 'shoulda-matchers', '>= 2.8'
24
+ spec.add_development_dependency 'appraisal'
25
+ spec.add_development_dependency 'bundler', '>= 1.5'
26
+ spec.add_development_dependency 'rake', '>= 10.1'
27
+ spec.add_development_dependency 'rspec', '>= 2.6'
28
+ spec.add_development_dependency 'pry'
28
29
  end