Class: EasyJSONMatcher::ValidationStep

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_json_matcher/validation_step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verify_with:) ⇒ ValidationStep

Returns a new instance of ValidationStep.



11
12
13
# File 'lib/easy_json_matcher/validation_step.rb', line 11

def initialize(verify_with:)
  @verifier = verify_with
end

Instance Attribute Details

#next_stepObject (readonly)

Returns the value of attribute next_step.



9
10
11
# File 'lib/easy_json_matcher/validation_step.rb', line 9

def next_step
  @next_step
end

#verifierObject (readonly)

Returns the value of attribute verifier.



9
10
11
# File 'lib/easy_json_matcher/validation_step.rb', line 9

def verifier
  @verifier
end

Instance Method Details

#>>(step) ⇒ Object



24
25
26
# File 'lib/easy_json_matcher/validation_step.rb', line 24

def >>(step)
  @next_step = step
end

#call(value:) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/easy_json_matcher/validation_step.rb', line 15

def call(value:)
  errors = []
  if verifier.call(value, errors) == false || is_tail?
    errors
  else
    errors + next_step.call(value: value)
  end
end

#concat(chain) ⇒ Object



28
29
30
# File 'lib/easy_json_matcher/validation_step.rb', line 28

def concat(chain)
  is_tail? ? self.>>(chain) : next_step.concat(chain)
end

#is_tail?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/easy_json_matcher/validation_step.rb', line 32

def is_tail?
  next_step.nil?
end