Class: Jet::Contract::Check
- Inherits:
-
Object
- Object
- Jet::Contract::Check
show all
- Defined in:
- lib/jet/contract/check.rb,
lib/jet/contract/check/set.rb
Defined Under Namespace
Modules: BuiltIn
Classes: Set
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, &check) ⇒ Check
Returns a new instance of Check.
12
13
14
15
16
|
# File 'lib/jet/contract/check.rb', line 12
def initialize(name, &check)
raise ArgumentError, "no block given" unless block_given?
@check = lambda(&check)
@name = name
end
|
Instance Attribute Details
#check ⇒ Object
Returns the value of attribute check.
10
11
12
|
# File 'lib/jet/contract/check.rb', line 10
def check
@check
end
|
#name ⇒ Object
Returns the value of attribute name.
10
11
12
|
# File 'lib/jet/contract/check.rb', line 10
def name
@name
end
|
Class Method Details
.[](key) ⇒ Object
6
7
8
|
# File 'lib/jet/contract/check.rb', line 6
def self.[](key)
BuiltIn[key]
end
|
Instance Method Details
#call(output, *args) ⇒ Object
18
19
20
21
22
|
# File 'lib/jet/contract/check.rb', line 18
def call(output, *args)
result = check.(output, *args)
return Result.success(output, args: args) if Jet.success?(result)
Result.failure(error(result), Jet.context(result, args: args, input: output))
end
|
#inspect ⇒ Object
24
25
26
|
# File 'lib/jet/contract/check.rb', line 24
def inspect
"#<#{self.class.name}:#{name}>"
end
|
#to_sym ⇒ Object
28
29
30
|
# File 'lib/jet/contract/check.rb', line 28
def to_sym
name
end
|