Class: Definition::Types::Or

Inherits:
Base
  • Object
show all
Includes:
Dsl
Defined in:
lib/definition/types/or.rb

Defined Under Namespace

Modules: Dsl

Instance Attribute Summary collapse

Attributes inherited from Base

#context, #name

Instance Method Summary collapse

Methods included from Dsl

#validate

Methods inherited from Base

#explain

Constructor Details

#initialize(name, *args) ⇒ Or

Returns a new instance of Or.



18
19
20
21
# File 'lib/definition/types/or.rb', line 18

def initialize(name, *args)
  @definitions = *args
  super(name)
end

Instance Attribute Details

#definitionsObject (readonly)

Returns the value of attribute definitions.



16
17
18
# File 'lib/definition/types/or.rb', line 16

def definitions
  @definitions
end

Instance Method Details

#conform(value) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/definition/types/or.rb', line 23

def conform(value)
  last_result = nil
  @definitions.each do |definition|
    last_result = definition.conform(value)
    return last_result if last_result.passed?
  end

  ConformResult.new(value, errors: [
                      ConformError.new(self,
                                       "None of the definitions are valid for '#{name}'."\
                                       " Errors for last tested definition:",
                                       sub_errors: last_result.error_tree)
                    ])
end

#error_rendererObject



38
39
40
# File 'lib/definition/types/or.rb', line 38

def error_renderer
  ErrorRenderers::Leaf
end