Class: Aequitas::Rule::Method

Inherits:
Aequitas::Rule show all
Defined in:
lib/aequitas/rule/method.rb

Instance Attribute Summary collapse

Attributes inherited from Aequitas::Rule

#attribute_name, #custom_message, #guard, #skip_condition

Attributes included from ValueObject

#equalizer

Instance Method Summary collapse

Methods inherited from Aequitas::Rule

#attribute_value, #execute?, rules_for, #skip?, #violation_data, #violation_info, #violation_values

Methods included from ValueObject

#equalize_on

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, options={})
  super

  @method         = options.fetch(:method,         attribute_name)
  @violation_type = options.fetch(:violation_type, :unsatisfied_condition)
end

Instance Attribute Details

#methodObject (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, error_message = resource.__send__(method)

  if result
    nil
  else
    Violation.new(resource, error_message, 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