Class: Jet::Contract::Check::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/jet/contract/check/set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*checks) ⇒ Set

Returns a new instance of Set.



9
10
11
12
13
# File 'lib/jet/contract/check/set.rb', line 9

def initialize(*checks)
  @checks = []
  checks.each { |c| add!(c) }
  @checks.freeze
end

Instance Attribute Details

#checksObject (readonly)

Returns the value of attribute checks.



7
8
9
# File 'lib/jet/contract/check/set.rb', line 7

def checks
  @checks
end

Instance Method Details

#call(output) ⇒ Object



15
16
17
18
19
20
# File 'lib/jet/contract/check/set.rb', line 15

def call(output)
  @checks.each do |(check, *args)|
    check.(output, *args).tap { |r| return r if Jet.failure?(r) }
  end
  Result.success(output)
end

#to_builderObject



22
23
24
# File 'lib/jet/contract/check/set.rb', line 22

def to_builder
  @checks.map { |(c, *args)| [c.name].concat(args) }
end