Class: Aequitas::Rule::Within
- Inherits:
-
Aequitas::Rule
- Object
- Aequitas::Rule
- Aequitas::Rule::Within
- Defined in:
- lib/aequitas/rule/within.rb
Instance Attribute Summary collapse
-
#set ⇒ Object
readonly
Returns the value of attribute set.
Attributes inherited from Aequitas::Rule
#attribute_name, #custom_message, #guard, #skip_condition
Attributes included from ValueObject
Class Method Summary collapse
-
.rules_for(attribute_name, options) ⇒ Object
TODO: move options normalization into the validator macros.
Instance Method Summary collapse
-
#initialize(attribute_name, options = {}) ⇒ Within
constructor
A new instance of Within.
- #valid?(resource) ⇒ Boolean
- #violation_data(resource) ⇒ Object
- #violation_type(resource) ⇒ Object
Methods inherited from Aequitas::Rule
#attribute_value, #execute?, #skip?, #validate, #violation_info, #violation_values
Methods included from ValueObject
Constructor Details
#initialize(attribute_name, options = {}) ⇒ Within
Returns a new instance of Within.
18 19 20 21 22 |
# File 'lib/aequitas/rule/within.rb', line 18 def initialize(attribute_name, ={}) super @set = .fetch(:set) end |
Instance Attribute Details
#set ⇒ Object (readonly)
Returns the value of attribute set.
16 17 18 |
# File 'lib/aequitas/rule/within.rb', line 16 def set @set end |
Class Method Details
.rules_for(attribute_name, options) ⇒ Object
TODO: move options normalization into the validator macros
10 11 12 |
# File 'lib/aequitas/rule/within.rb', line 10 def self.rules_for(attribute_name, ) Array(new(attribute_name, )) end |
Instance Method Details
#valid?(resource) ⇒ Boolean
24 25 26 27 28 |
# File 'lib/aequitas/rule/within.rb', line 24 def valid?(resource) value = attribute_value(resource) skip?(value) || set.include?(value) end |
#violation_data(resource) ⇒ Object
34 35 36 |
# File 'lib/aequitas/rule/within.rb', line 34 def violation_data(resource) [ [ :set, set.to_a.join(', ') ] ] end |
#violation_type(resource) ⇒ Object
30 31 32 |
# File 'lib/aequitas/rule/within.rb', line 30 def violation_type(resource) :inclusion end |