active_interaction 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05a744023cf02eb1f2ea70d41ca68b807779e13a
4
- data.tar.gz: 455646aa8861af2545cd805f4eafe0856a9ff8f5
3
+ metadata.gz: c3902ef15c3ae5f01fc8488e949ebeadea266a24
4
+ data.tar.gz: 1465a2163042d03ca351af7fd735b9cfa7404aa1
5
5
  SHA512:
6
- metadata.gz: 64c694eb64b7550b224b12d271463ef508e8d23fa6edbb295f97374a9693010d2cfbd0be22c6a98c66aa0dd1b1e4ff58893e524b93024be8dee39ee6ab841a4a
7
- data.tar.gz: d657ef014a9e0bf547f83402e0d8becc33d1fad871bbfb26d8680fcf37a0d5ad9cad5fe263d7b43105f584caad4b98a349050dc41115bb3de70231cf42788676
6
+ metadata.gz: 4991f73428cf14bf5793fc5ad76ad8aa298da83ec030135d15770a459f42396f961f5eb9042dcf46531c63dd87255c697a5fb6d3e497164d2272e8d58de9d6ef
7
+ data.tar.gz: 0095a818c2d81597499af06a6967097ffdf2953089cf91c2a4ef1de196a57b95e7d3de812c7c722faa66139faeca19c83093d2043fa64c0ce828853e3f902dd3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [1.6.0][] (2015-05-06)
2
+
3
+ ## Added
4
+
5
+ - Added `object` as an alias for `model`.
6
+ - Added symbol support to `add`.
7
+ - Added `details` as an alternative to `symbolic`.
8
+
9
+ ## Changed
10
+
11
+ - Deprecated `model` in favor of `object`.
12
+ - Deprecated `add_sym` in favor of `add`.
13
+ - Deprecated `transaction`.
14
+ - Deprecated `symbolic` in favor of `details`.
15
+
1
16
  # [1.5.1][] (2015-04-28)
2
17
 
3
18
  ## Fixed
@@ -381,6 +396,7 @@
381
396
 
382
397
  - Initial release.
383
398
 
399
+ [1.6.0]: https://github.com/orgsync/active_interaction/compare/v1.5.1...v1.6.0
384
400
  [1.5.1]: https://github.com/orgsync/active_interaction/compare/v1.5.0...v1.5.1
385
401
  [1.5.0]: https://github.com/orgsync/active_interaction/compare/v1.4.1...v1.5.0
386
402
  [1.4.1]: https://github.com/orgsync/active_interaction/compare/v1.4.0...v1.4.1
data/README.md CHANGED
@@ -75,13 +75,13 @@ Read more on [the project page][] or check out [the full documentation][].
75
75
  Add it to your Gemfile:
76
76
 
77
77
  ``` rb
78
- gem 'active_interaction', '~> 1.5'
78
+ gem 'active_interaction', '~> 1.6'
79
79
  ```
80
80
 
81
81
  Or install it manually:
82
82
 
83
83
  ``` sh
84
- $ gem install active_interaction --version '~> 1.5'
84
+ $ gem install active_interaction --version '~> 1.6'
85
85
  ```
86
86
 
87
87
  This project uses [Semantic Versioning][]. Check out [the change log][] for a
@@ -2,6 +2,28 @@
2
2
 
3
3
  require 'active_model'
4
4
 
5
+ # Manage application specific business logic.
6
+ #
7
+ # @author Aaron Lasseigne <aaron.lasseigne@gmail.com>
8
+ # @author Taylor Fausak <taylor@fausak.me>
9
+ #
10
+ # @since 1.0.0
11
+ #
12
+ # @version 1.6.0
13
+ module ActiveInteraction
14
+ DEPRECATOR =
15
+ if ::ActiveSupport::Deprecation.respond_to?(:new)
16
+ ::ActiveSupport::Deprecation.new('2', 'ActiveInteraction')
17
+ end
18
+ private_constant :DEPRECATOR
19
+
20
+ def self.deprecate(klass, method, message = nil)
21
+ options = { method => message }
22
+ options.merge!(deprecator: DEPRECATOR) if DEPRECATOR
23
+ klass.deprecate(options)
24
+ end
25
+ end
26
+
5
27
  require 'active_interaction/version'
6
28
  require 'active_interaction/errors'
7
29
 
@@ -43,13 +65,3 @@ require 'active_interaction/backports'
43
65
 
44
66
  I18n.load_path.unshift(*Dir[File.expand_path(
45
67
  File.join(%w[active_interaction locale *.yml]), File.dirname(__FILE__))])
46
-
47
- # Manage application specific business logic.
48
- #
49
- # @author Aaron Lasseigne <aaron.lasseigne@gmail.com>
50
- # @author Taylor Fausak <taylor@fausak.me>
51
- #
52
- # @since 1.0.0
53
- #
54
- # @version 1.5.1
55
- module ActiveInteraction end
@@ -17,16 +17,15 @@ module ActiveInteraction
17
17
  # Required for Rails < 3.2.13.
18
18
  protected :initialize_dup
19
19
  end
20
- end
21
20
 
22
- # @private
23
- class Hash
24
- # Required for Rails < 4.0.0.
25
- def transform_keys
26
- result = {}
27
- each_key do |key|
28
- result[yield(key)] = self[key]
21
+ class HashFilter # rubocop:disable Style/Documentation
22
+ # Required for Rails < 4.0.0.
23
+ def self.transform_keys(hash, &block)
24
+ return hash.transform_keys(&block) if hash.respond_to?(:transform_keys)
25
+
26
+ result = {}
27
+ hash.each_key { |key| result[block.call(key)] = hash[key] }
28
+ result
29
29
  end
30
- result
31
- end unless method_defined?(:transform_keys)
30
+ end
32
31
  end
@@ -121,6 +121,11 @@ module ActiveInteraction
121
121
  end
122
122
  end
123
123
 
124
+ def model(*)
125
+ super
126
+ end
127
+ ActiveInteraction.deprecate self, :model, 'use `object` instead'
128
+
124
129
  private
125
130
 
126
131
  # @param klass [Class]
@@ -249,7 +254,7 @@ module ActiveInteraction
249
254
  def type_check
250
255
  run_callbacks(:type_check) do
251
256
  Validation.validate(self.class.filters, inputs).each do |error|
252
- errors.add_sym(*error)
257
+ errors.add(*error)
253
258
  end
254
259
  end
255
260
  end
@@ -41,7 +41,8 @@ module ActiveInteraction
41
41
  module ClassMethods # rubocop:disable Style/Documentation
42
42
  # @param klass [Class]
43
43
  def inherited(klass)
44
- klass.transaction(transaction?, transaction_options.dup)
44
+ klass.transaction_without_deprecation(
45
+ transaction?, transaction_options.dup)
45
46
 
46
47
  super
47
48
  end
@@ -56,6 +57,7 @@ module ActiveInteraction
56
57
 
57
58
  nil
58
59
  end
60
+ ActiveInteraction.deprecate self, :transaction
59
61
 
60
62
  # @return [Boolean]
61
63
  def transaction?
@@ -96,13 +96,28 @@ module ActiveInteraction
96
96
  #
97
97
  # @return [Hash{Symbol => Array<Symbol>}]
98
98
  attr_reader :symbolic
99
+ ActiveInteraction.deprecate self, :symbolic, 'use `details` instead'
100
+
101
+ def details
102
+ h = Hash.new([]).with_indifferent_access
103
+ @symbolic.each { |k, vs| vs.each { |v| h[k] += [{ error: v }] } }
104
+ h
105
+ end
106
+
107
+ alias_method :add_without_details, :add
108
+ def add_with_details(attribute, message = :invalid, options = {})
109
+ message = message.call if message.respond_to?(:call)
110
+ @symbolic[attribute] += [message] if message.is_a?(Symbol)
111
+ add_without_details(attribute, message, options)
112
+ end
113
+ alias_method :add, :add_with_details
99
114
 
100
115
  # Adds a symbolic error message to an attribute.
101
116
  #
102
117
  # @example
103
118
  # errors.add_sym(:attribute)
104
- # errors.symbolic
105
- # # => {:attribute=>[:invalid]}
119
+ # errors.details
120
+ # # => {:attribute=>[{:error=>:invalid}]}
106
121
  # errors.messages
107
122
  # # => {:attribute=>["is invalid"]}
108
123
  #
@@ -115,10 +130,11 @@ module ActiveInteraction
115
130
  #
116
131
  # @see ActiveModel::Errors#add
117
132
  def add_sym(attribute, symbol = :invalid, message = nil, options = {})
118
- add(attribute, message || symbol, options)
133
+ add_without_details(attribute, message || symbol, options)
119
134
 
120
- symbolic[attribute] += [symbol]
135
+ @symbolic[attribute] += [symbol]
121
136
  end
137
+ ActiveInteraction.deprecate self, :add_sym, 'use `add` instead'
122
138
 
123
139
  # @see ActiveModel::Errors#initialize
124
140
  #
@@ -133,7 +149,8 @@ module ActiveInteraction
133
149
  #
134
150
  # @private
135
151
  def initialize_dup(other)
136
- @symbolic = other.symbolic.with_indifferent_access
152
+ @symbolic = Hash.new([]).with_indifferent_access
153
+ other.details.each { |k, vs| vs.each { |v| @symbolic[k] += [v[:error]] } }
137
154
 
138
155
  super
139
156
  end
@@ -142,7 +159,7 @@ module ActiveInteraction
142
159
  #
143
160
  # @private
144
161
  def clear
145
- symbolic.clear
162
+ @symbolic.clear
146
163
 
147
164
  super
148
165
  end
@@ -154,7 +171,7 @@ module ActiveInteraction
154
171
  # @return [Errors]
155
172
  def merge!(other)
156
173
  merge_messages!(other)
157
- merge_symbolic!(other) if other.respond_to?(:symbolic)
174
+ merge_details!(other) if other.respond_to?(:details)
158
175
  self
159
176
  end
160
177
 
@@ -168,12 +185,13 @@ module ActiveInteraction
168
185
  end
169
186
  end
170
187
 
171
- def merge_symbolic!(other)
172
- other.symbolic.each do |attribute, symbols|
173
- symbols.each do |symbol|
174
- next if symbolic[attribute].include?(symbol)
188
+ def merge_details!(other)
189
+ other.details.each do |attribute, hashes|
190
+ hashes.each do |hash|
191
+ error = hash[:error]
192
+ next if @symbolic[attribute].include?(error)
175
193
 
176
- symbolic[attribute] += [symbol]
194
+ @symbolic[attribute] += [error]
177
195
  end
178
196
  end
179
197
  end
@@ -54,6 +54,11 @@ module ActiveInteraction
54
54
  end
55
55
  end
56
56
 
57
+ def model(*)
58
+ super
59
+ end
60
+ ActiveInteraction.deprecate self, :model, 'use `object` instead'
61
+
57
62
  private
58
63
 
59
64
  # @return [Array<Class>]
@@ -52,6 +52,11 @@ module ActiveInteraction
52
52
  end
53
53
  end
54
54
 
55
+ def model(*)
56
+ super
57
+ end
58
+ ActiveInteraction.deprecate self, :model, 'use `object` instead'
59
+
55
60
  private
56
61
 
57
62
  def clean_value(h, name, filter, value)
@@ -76,7 +81,7 @@ module ActiveInteraction
76
81
  end
77
82
 
78
83
  def stringify_the_symbol_keys(hash)
79
- hash.transform_keys { |key| key.is_a?(Symbol) ? key.to_s : key }
84
+ self.class.transform_keys(hash) { |k| k.is_a?(Symbol) ? k.to_s : k }
80
85
  end
81
86
  end
82
87
  end
@@ -19,6 +19,7 @@ module ActiveInteraction
19
19
  # @private
20
20
  class ModelFilter < Filter
21
21
  register :model
22
+ register :object
22
23
 
23
24
  def cast(value, reconstantize = true)
24
25
  @klass ||= klass
@@ -18,6 +18,7 @@ en:
18
18
  integer: integer
19
19
  interface: interface
20
20
  model: model
21
+ object: object
21
22
  string: string
22
23
  symbol: symbol
23
24
  time: time
@@ -25,10 +25,10 @@ module ActiveInteraction
25
25
  def error_args(filter, error)
26
26
  case error
27
27
  when InvalidNestedValueError
28
- [filter.name, :invalid_nested, nil,
28
+ [filter.name, :invalid_nested,
29
29
  name: error.filter_name.inspect, value: error.input_value.inspect]
30
30
  when InvalidValueError
31
- [filter.name, :invalid_type, nil, type: type(filter)]
31
+ [filter.name, :invalid_type, type: type(filter)]
32
32
  when MissingValueError
33
33
  [filter.name, :missing]
34
34
  end
@@ -5,5 +5,5 @@ module ActiveInteraction
5
5
  # The version number.
6
6
  #
7
7
  # @return [Gem::Version]
8
- VERSION = Gem::Version.new('1.5.1')
8
+ VERSION = Gem::Version.new('1.6.0')
9
9
  end
@@ -40,30 +40,30 @@ describe ActiveInteraction::Errors do
40
40
 
41
41
  context 'calling #add' do
42
42
  before do
43
- allow(errors).to receive(:add)
43
+ allow(errors).to receive(:add_without_details)
44
44
  end
45
45
 
46
46
  it 'with the default' do
47
47
  errors.add_sym(:attribute)
48
- expect(errors).to have_received(:add).once
48
+ expect(errors).to have_received(:add_without_details).once
49
49
  .with(:attribute, :invalid, {})
50
50
  end
51
51
 
52
52
  it 'with a symbol' do
53
53
  errors.add_sym(:attribute, :symbol)
54
- expect(errors).to have_received(:add).once
54
+ expect(errors).to have_received(:add_without_details).once
55
55
  .with(:attribute, :symbol, {})
56
56
  end
57
57
 
58
58
  it 'with a symbol and message' do
59
59
  errors.add_sym(:attribute, :symbol, 'message')
60
- expect(errors).to have_received(:add).once
60
+ expect(errors).to have_received(:add_without_details).once
61
61
  .with(:attribute, 'message', {})
62
62
  end
63
63
 
64
64
  it 'with a symbol, message and options' do
65
65
  errors.add_sym(:attribute, :symbol, 'message', key: :value)
66
- expect(errors).to have_received(:add).once
66
+ expect(errors).to have_received(:add_without_details).once
67
67
  .with(:attribute, 'message', key: :value)
68
68
  end
69
69
  end
@@ -42,7 +42,7 @@ describe ActiveInteraction::Validation do
42
42
  type = I18n.translate(
43
43
  "#{ActiveInteraction::Base.i18n_scope}.types.#{filter.class.slug}")
44
44
 
45
- expect(result).to eql [[filter.name, :invalid_type, nil, type: type]]
45
+ expect(result).to eql [[filter.name, :invalid_type, type: type]]
46
46
  end
47
47
  end
48
48
 
@@ -65,7 +65,6 @@ describe ActiveInteraction::Validation do
65
65
  expect(result).to eql [[
66
66
  filter.name,
67
67
  :invalid_nested,
68
- nil,
69
68
  { name: name.inspect, value: value.inspect }
70
69
  ]]
71
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_interaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Lasseigne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-28 00:00:00.000000000 Z
12
+ date: 2015-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel