Class: Aequitas::Rule::Method
- Inherits:
-
Aequitas::Rule
- Object
- Aequitas::Rule
- Aequitas::Rule::Method
- Defined in:
- lib/aequitas/rule/method.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Attributes inherited from Aequitas::Rule
#attribute_name, #custom_message, #guard, #skip_condition
Attributes included from ValueObject
Instance Method Summary collapse
-
#initialize(attribute_name, options = {}) ⇒ Method
constructor
A new instance of Method.
- #validate(resource) ⇒ Object
- #violation_type(resource) ⇒ Object
Methods inherited from Aequitas::Rule
#attribute_value, #execute?, rules_for, #skip?, #violation_data, #violation_info, #violation_values
Methods included from ValueObject
Constructor Details
#initialize(attribute_name, options = {}) ⇒ Method
Returns a new instance of Method.
13 14 15 16 17 18 |
# File 'lib/aequitas/rule/method.rb', line 13 def initialize(attribute_name, ={}) super @method = .fetch(:method, attribute_name) @violation_type = .fetch(:violation_type, :unsatisfied_condition) end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
11 12 13 |
# File 'lib/aequitas/rule/method.rb', line 11 def method @method end |
Instance Method Details
#validate(resource) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/aequitas/rule/method.rb', line 20 def validate(resource) result, = resource.__send__(method) if result nil else Violation.new(resource, , self) end end |
#violation_type(resource) ⇒ Object
30 31 32 |
# File 'lib/aequitas/rule/method.rb', line 30 def violation_type(resource) @violation_type end |