Class: Igniter::Contract::ResultReader
- Inherits:
-
Object
- Object
- Igniter::Contract::ResultReader
show all
- Defined in:
- lib/igniter/contracts/contract.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ResultReader.
6
7
8
9
|
# File 'lib/igniter/contracts/contract.rb', line 6
def initialize(outputs)
@outputs = outputs
freeze
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/igniter/contracts/contract.rb', line 21
def method_missing(name, *args, &block)
return output(name) if args.empty? && block.nil? && @outputs.key?(name)
raise KeyError, "unknown contract output #{name}" if args.empty? && block.nil?
super
end
|
Instance Method Details
#output(name) ⇒ Object
11
12
13
14
15
|
# File 'lib/igniter/contracts/contract.rb', line 11
def output(name)
@outputs.fetch(name.to_sym)
rescue KeyError
raise KeyError, "unknown contract output #{name}"
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
28
29
30
|
# File 'lib/igniter/contracts/contract.rb', line 28
def respond_to_missing?(name, include_private = false)
@outputs.key?(name) || super
end
|
#to_h ⇒ Object
17
18
19
|
# File 'lib/igniter/contracts/contract.rb', line 17
def to_h
@outputs.to_h
end
|