active_interaction 1.2.1 → 1.2.2

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: 0b77e2393588e6b32887a4a38847e14b8f347191
4
- data.tar.gz: ef3b09ab34ef2b7937a457f5cab2648f0cb7e8cc
3
+ metadata.gz: 8da6c6009b0e73aeec0afbc524e94c27dde01260
4
+ data.tar.gz: c34f2110a50219b87ba1e22cda387f0f429db7d2
5
5
  SHA512:
6
- metadata.gz: 5af88c5f9d4b7da0b6e6adc2039d393e0b2fdbac83268b28a8015dce6cf926ec59465201e298e90ce6f4a8f6cd77d5d3641bd787eaaaf0cd2e314646237f66c3
7
- data.tar.gz: ebdfcf778480fa4874e04551d07cb2495df8845238d1b79868c0905c77e309f5c9130892c888c241786cf6d7d78b3b914d5bdf374ef513fb78b1e3c8dcd2fdba
6
+ metadata.gz: 274c345305f246fc6ae9078846d317cbb7e19b4781d18e73f20ade3336ca77f34008e7e8ca65985a5b3573a0742d8c79a25e9c1ffcc707d947ee5316e965fcec
7
+ data.tar.gz: ff0bf22dfb87c3774a3a9397943dfa02959355b7773dd87d1d188ac7ac1df47a6014888fcba67ef1286200f6df93f98e96c008c3acf0234d0c87f83780e0464e
@@ -1,5 +1,11 @@
1
1
  # [Master][]
2
2
 
3
+ # [1.2.2][] (2014-05-07)
4
+
5
+ - Fix a bug that raised `NameError`s when there were invalid nested hash
6
+ errors.
7
+ - Add missing translation for symbol filters.
8
+
3
9
  # [1.2.1][] (2014-05-02)
4
10
 
5
11
  - Fix a bug that marked model inputs as invalid even if they returned true for
@@ -199,7 +205,8 @@
199
205
 
200
206
  - Initial release.
201
207
 
202
- [master]: https://github.com/orgsync/active_interaction/compare/v1.2.1...master
208
+ [master]: https://github.com/orgsync/active_interaction/compare/v1.2.2...master
209
+ [1.2.2]: https://github.com/orgsync/active_interaction/compare/v1.2.1...v1.2.2
203
210
  [1.2.1]: https://github.com/orgsync/active_interaction/compare/v1.2.0...v1.2.1
204
211
  [1.2.0]: https://github.com/orgsync/active_interaction/compare/v1.1.7...v1.2.0
205
212
  [1.1.7]: https://github.com/orgsync/active_interaction/compare/v1.1.6...v1.1.7
@@ -39,8 +39,9 @@ require 'active_interaction/base'
39
39
 
40
40
  require 'active_interaction/backports'
41
41
 
42
- I18n.load_path << File.expand_path(
43
- File.join(%w[active_interaction locale en.yml]), File.dirname(__FILE__))
42
+ I18n.load_path += Dir[File.expand_path(
43
+ File.join(%w[active_interaction locale *.yml]), File.dirname(__FILE__))]
44
+ I18n.default_locale = :en
44
45
 
45
46
  # Manage application specific business logic.
46
47
  #
@@ -49,5 +50,5 @@ I18n.load_path << File.expand_path(
49
50
  #
50
51
  # @since 1.0.0
51
52
  #
52
- # @version 1.2.1
53
+ # @version 1.2.2
53
54
  module ActiveInteraction end
@@ -12,10 +12,6 @@ module ActiveInteraction
12
12
 
13
13
  # Describes an input filter for an interaction.
14
14
  class Filter
15
- # @return [Regexp]
16
- CLASS_REGEXP = /\AActiveInteraction::([A-Z]\w*)Filter\z/
17
- private_constant :CLASS_REGEXP
18
-
19
15
  # @return [Hash{Symbol => Class}]
20
16
  CLASSES = {}
21
17
  private_constant :CLASSES
@@ -32,6 +28,9 @@ module ActiveInteraction
32
28
  undef_method :hash
33
29
 
34
30
  class << self
31
+ # @return [Symbol]
32
+ attr_reader :slug
33
+
35
34
  # Get the filter associated with a symbol.
36
35
  #
37
36
  # @example
@@ -52,35 +51,14 @@ module ActiveInteraction
52
51
  CLASSES.fetch(slug) { fail MissingFilterError, slug.inspect }
53
52
  end
54
53
 
55
- # Convert the class name into a short symbol.
56
- #
57
- # @example
58
- # ActiveInteraction::BooleanFilter.slug
59
- # # => :boolean
60
- # @example
61
- # ActiveInteraction::Filter.slug
62
- # # => ActiveInteraction::InvalidClassError: ActiveInteraction::Filter
63
- #
64
- # @return [Symbol]
65
- #
66
- # @raise [InvalidClassError] If the filter doesn't have a valid slug.
67
- #
68
- # @see .factory
69
- def slug
70
- return @slug if defined?(@slug)
71
-
72
- match = name[CLASS_REGEXP, 1]
73
- fail InvalidClassError, name unless match
74
- @slug = match.underscore.to_sym
75
- end
54
+ private
76
55
 
56
+ # @param slug [Symbol]
77
57
  # @param klass [Class]
78
58
  #
79
- # @private
80
- def inherited(klass)
81
- CLASSES[klass.slug] = klass
82
- rescue InvalidClassError
83
- CLASSES[klass.name.to_sym] = klass
59
+ # @return [Class]
60
+ def register(slug)
61
+ CLASSES[@slug = slug] = self
84
62
  end
85
63
  end
86
64
 
@@ -25,6 +25,8 @@ module ActiveInteraction
25
25
  class ArrayFilter < Filter
26
26
  include Missable
27
27
 
28
+ register :array
29
+
28
30
  def cast(value)
29
31
  case value
30
32
  when Array
@@ -16,6 +16,8 @@ module ActiveInteraction
16
16
 
17
17
  # @private
18
18
  class BooleanFilter < Filter
19
+ register :boolean
20
+
19
21
  def cast(value)
20
22
  case value
21
23
  when FalseClass, '0', /\Afalse\z/i
@@ -19,5 +19,6 @@ module ActiveInteraction
19
19
 
20
20
  # @private
21
21
  class DateFilter < AbstractDateTimeFilter
22
+ register :date
22
23
  end
23
24
  end
@@ -19,6 +19,8 @@ module ActiveInteraction
19
19
 
20
20
  # @private
21
21
  class DateTimeFilter < AbstractDateTimeFilter
22
+ register :date_time
23
+
22
24
  def database_column_type
23
25
  :datetime
24
26
  end
@@ -17,6 +17,8 @@ module ActiveInteraction
17
17
 
18
18
  # @private
19
19
  class DecimalFilter < AbstractNumericFilter
20
+ register :decimal
21
+
20
22
  def cast(value)
21
23
  case value
22
24
  when Numeric
@@ -16,6 +16,8 @@ module ActiveInteraction
16
16
 
17
17
  # @private
18
18
  class FileFilter < Filter
19
+ register :file
20
+
19
21
  def cast(value)
20
22
  value = extract_file(value)
21
23
 
@@ -15,5 +15,6 @@ module ActiveInteraction
15
15
 
16
16
  # @private
17
17
  class FloatFilter < AbstractNumericFilter
18
+ register :float
18
19
  end
19
20
  end
@@ -27,6 +27,8 @@ module ActiveInteraction
27
27
  class HashFilter < Filter
28
28
  include Missable
29
29
 
30
+ register :hash
31
+
30
32
  def cast(value)
31
33
  case value
32
34
  when Hash
@@ -15,5 +15,6 @@ module ActiveInteraction
15
15
 
16
16
  # @private
17
17
  class IntegerFilter < AbstractNumericFilter
18
+ register :integer
18
19
  end
19
20
  end
@@ -18,6 +18,8 @@ module ActiveInteraction
18
18
 
19
19
  # @private
20
20
  class ModelFilter < Filter
21
+ register :model
22
+
21
23
  def cast(value, reconstantize = true)
22
24
  @klass ||= klass
23
25
 
@@ -18,6 +18,8 @@ module ActiveInteraction
18
18
 
19
19
  # @private
20
20
  class StringFilter < Filter
21
+ register :string
22
+
21
23
  def cast(value)
22
24
  case value
23
25
  when String
@@ -14,6 +14,8 @@ module ActiveInteraction
14
14
 
15
15
  # @private
16
16
  class SymbolFilter < Filter
17
+ register :symbol
18
+
17
19
  def cast(value)
18
20
  case value
19
21
  when Symbol
@@ -21,6 +21,8 @@ module ActiveInteraction
21
21
 
22
22
  # @private
23
23
  class TimeFilter < AbstractDateTimeFilter
24
+ register :time
25
+
24
26
  alias_method :_klass, :klass
25
27
  private :_klass
26
28
 
@@ -18,4 +18,5 @@ en:
18
18
  integer: integer
19
19
  model: model
20
20
  string: string
21
+ symbol: symbol
21
22
  time: time
@@ -26,7 +26,7 @@ module ActiveInteraction
26
26
  case error
27
27
  when InvalidNestedValueError
28
28
  [filter.name, :invalid_nested, nil,
29
- name: e.filter_name.inspect, value: e.input_value.inspect]
29
+ name: error.filter_name.inspect, value: error.input_value.inspect]
30
30
  when InvalidValueError
31
31
  [filter.name, :invalid_type, nil, type: type(filter)]
32
32
  when MissingValueError
@@ -5,5 +5,5 @@ module ActiveInteraction
5
5
  # The version number.
6
6
  #
7
7
  # @return [Gem::Version]
8
- VERSION = Gem::Version.new('1.2.1')
8
+ VERSION = Gem::Version.new('1.2.2')
9
9
  end
@@ -2,11 +2,6 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- module ActiveInteraction
6
- class ATestFilter < ActiveInteraction::Filter; end
7
- end
8
- class ATestFilter < ActiveInteraction::Filter; end
9
-
10
5
  describe ActiveInteraction::Filter, :filter do
11
6
  include_context 'filters'
12
7
 
@@ -16,33 +11,30 @@ describe ActiveInteraction::Filter, :filter do
16
11
  end
17
12
  end
18
13
 
19
- context ActiveInteraction::ATestFilter do
20
- it_behaves_like 'a filter'
21
-
22
- let(:described_class) { ActiveInteraction::ATestFilter }
14
+ context 'with an unregistered subclass' do
15
+ let(:described_class) { Class.new(ActiveInteraction::Filter) }
23
16
 
24
17
  describe '.slug' do
25
- it 'returns a slug representing the class' do
26
- expect(described_class.slug).to eql :a_test
18
+ it 'is nil' do
19
+ expect(described_class.slug).to be_nil
27
20
  end
28
21
  end
29
22
  end
30
23
 
31
- context ATestFilter do
32
- let(:described_class) { ATestFilter }
24
+ context 'with a registered subclass' do
25
+ it_behaves_like 'a filter'
33
26
 
34
- describe '.factory' do
35
- it 'returns a Filter' do
36
- expect(described_class.factory(described_class.name.to_sym))
37
- .to eql described_class
27
+ let(:described_class) do
28
+ s = slug
29
+ Class.new(ActiveInteraction::Filter) do
30
+ register s
38
31
  end
39
32
  end
33
+ let(:slug) { SecureRandom.hex.to_sym }
40
34
 
41
35
  describe '.slug' do
42
- it 'raises an error' do
43
- expect do
44
- described_class.slug
45
- end.to raise_error ActiveInteraction::InvalidClassError
36
+ it 'returns the registered slug' do
37
+ expect(described_class.slug).to eql slug
46
38
  end
47
39
  end
48
40
  end
@@ -11,19 +11,9 @@ end
11
11
  describe I18nInteraction do
12
12
  include_context 'interactions'
13
13
 
14
- TYPES = %w[
15
- array
16
- boolean
17
- date
18
- date_time
19
- file
20
- float
21
- hash
22
- integer
23
- model
24
- string
25
- time
26
- ]
14
+ TYPES = ActiveInteraction::Filter
15
+ .const_get(:CLASSES)
16
+ .map { |slug, _| slug.to_s }
27
17
 
28
18
  shared_examples 'translation' do
29
19
  context 'types' do
@@ -49,10 +49,27 @@ describe ActiveInteraction::Validation do
49
49
  context 'MissingValueError' do
50
50
  let(:exception) { ActiveInteraction::MissingValueError }
51
51
 
52
- it 'returns an :msising error' do
52
+ it 'returns a :missing error' do
53
53
  expect(result).to eql [[filter.name, :missing]]
54
54
  end
55
55
  end
56
+
57
+ context 'InvalidNestedValueError' do
58
+ let(:exception) do
59
+ ActiveInteraction::InvalidNestedValueError.new(name, value)
60
+ end
61
+ let(:name) { SecureRandom.hex.to_sym }
62
+ let(:value) { double }
63
+
64
+ it 'returns an :invalid_nested error' do
65
+ expect(result).to eql [[
66
+ filter.name,
67
+ :invalid_nested,
68
+ nil,
69
+ { name: name.inspect, value: value.inspect }
70
+ ]]
71
+ end
72
+ end
56
73
  end
57
74
  end
58
75
  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.2.1
4
+ version: 1.2.2
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: 2014-05-02 00:00:00.000000000 Z
12
+ date: 2014-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel