business_flow 0.4.3 → 0.4.4

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: a606f274a7654da5d5ea5bcecec5ad78e6694a94
4
- data.tar.gz: 16864e345d6f8b536dd7ae20631b4782511e349f
3
+ metadata.gz: c64b686d7c5bc163fe6b12e9dbe8f697a93818be
4
+ data.tar.gz: 3e689698a828b138adcacde97be3fd97724814ee
5
5
  SHA512:
6
- metadata.gz: 067107876f8431cec4f40545b53ef44706127b64854ba8f130b8d65c1e378971c43ca3f642dc054acca7f80cfef205154b2e4cc82ad2424e7a399d3b8034a65f
7
- data.tar.gz: 73ead3612688678e0490910751edc18f6a535e2e6fe8155c7222c4465771b4860631d166984f25f6ba6f99bcb18ed169cda0288980b13479e79e021fced3dd9f
6
+ metadata.gz: 28e9939de69fa659e98f87e26fc7454fac38b597f6c985d6f47cb56249825752c0992596b282ae22b2f54111afc04cfdf52417ebe8336443918dac0762be52fc
7
+ data.tar.gz: 4e72d98e7422b5c3738a82d9a7d127d41aaf11e9a8903b2d78966442928ea1429838a45ebfc8d1b26c30a866b567e67b5e07450f897b029794c080f414329b40
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- business_flow (0.4.3)
4
+ business_flow (0.4.4)
5
5
  activemodel (>= 3.0)
6
6
  activesupport (>= 3.0)
7
7
 
@@ -8,6 +8,8 @@ module BusinessFlow
8
8
  # was initialized with. The provided .call will instantiate the including
9
9
  # class with a parameter_object as the only argument.
10
10
  module ClassMethods
11
+ attr_reader :requirements
12
+
11
13
  # Requires that a field be retrievable from the initialization parameters
12
14
  #
13
15
  # This will only require that the field is not nil. The field may still
@@ -15,7 +17,8 @@ module BusinessFlow
15
17
  #
16
18
  # @param fields The fields required from the initialization parameters
17
19
  def needs(*fields)
18
- validates_with NotNilValidator, attributes: fields
20
+ @requirements ||= []
21
+ @requirements.push(*fields)
19
22
  wants(*fields)
20
23
  end
21
24
 
@@ -72,6 +75,7 @@ module BusinessFlow
72
75
  # See above -- that this is an alias is considered public API.
73
76
  alias invariant validates
74
77
  end
78
+ validates_with NotNilValidator
75
79
  end
76
80
  end
77
81
 
@@ -1,11 +1,15 @@
1
1
  module BusinessFlow
2
2
  # Validate that a given value is not nil, but allow blank/empty values.
3
- class NotNilValidator < ActiveModel::EachValidator
3
+ class NotNilValidator < ActiveModel::Validator
4
4
  # :reek:NilCheck :reek:UtilityFunction
5
5
  # Dear reek -- I didn't decided the ActiveModel Validator API, I just
6
6
  # have to live with it.
7
- def validate_each(record, attribute, value)
8
- record.errors[attribute] << 'must not be nil' if value.nil?
7
+ def validate(record)
8
+ requirements = record.class.requirements || []
9
+ requirements.each do |attribute|
10
+ value = record.read_attribute_for_validation(attribute)
11
+ record.errors[attribute] << 'must not be nil' if value.nil?
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module BusinessFlow
2
- VERSION = '0.4.3'.freeze
2
+ VERSION = '0.4.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Scarborough
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-16 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel