Class: Aequitas::Rule::Block
- Inherits:
-
Aequitas::Rule
- Object
- Aequitas::Rule
- Aequitas::Rule::Block
- Defined in:
- lib/aequitas/rule/block.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Attributes inherited from Aequitas::Rule
#attribute_name, #custom_message, #guard, #skip_condition
Attributes included from ValueObject
Instance Method Summary collapse
-
#initialize(attribute_name, options, &block) ⇒ Block
constructor
A new instance of Block.
- #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, &block) ⇒ Block
Returns a new instance of Block.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/aequitas/rule/block.rb', line 11 def initialize(attribute_name, , &block) unless block_given? raise ArgumentError, 'cannot initialize a Block validator without a block' end super @block = block @violation_type = .fetch(:violation_type, :unsatisfied_condition) end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
9 10 11 |
# File 'lib/aequitas/rule/block.rb', line 9 def block @block end |
Instance Method Details
#validate(resource) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/aequitas/rule/block.rb', line 22 def validate(resource) result, = resource.instance_eval(&self.block) if result nil else Violation.new(resource, , self) end end |
#violation_type(resource) ⇒ Object
32 33 34 |
# File 'lib/aequitas/rule/block.rb', line 32 def violation_type(resource) @violation_type end |