Class: Plumb::InterfaceClass
- Inherits:
-
Object
- Object
- Plumb::InterfaceClass
- Includes:
- Steppable
- Defined in:
- lib/plumb/interface_class.rb
Instance Attribute Summary collapse
-
#method_names ⇒ Object
readonly
Returns the value of attribute method_names.
Attributes included from Steppable
Instance Method Summary collapse
- #call(result) ⇒ Object
-
#initialize(method_names = []) ⇒ InterfaceClass
constructor
A new instance of InterfaceClass.
- #of(*args) ⇒ Object (also: #[])
Methods included from Steppable
#===, #>>, #as_node, #build, #check, #defer, #freeze, included, #inspect, #invalid, #invoke, #match, #meta, #node_name, #not, #pipeline, #policy, #to_s, #transform, #value, wrap, #|
Methods included from Callable
Constructor Details
#initialize(method_names = []) ⇒ InterfaceClass
Returns a new instance of InterfaceClass.
11 12 13 14 |
# File 'lib/plumb/interface_class.rb', line 11 def initialize(method_names = []) @method_names = method_names freeze end |
Instance Attribute Details
#method_names ⇒ Object (readonly)
Returns the value of attribute method_names.
9 10 11 |
# File 'lib/plumb/interface_class.rb', line 9 def method_names @method_names end |
Instance Method Details
#call(result) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/plumb/interface_class.rb', line 27 def call(result) obj = result.value missing_methods = @method_names.reject { |m| obj.respond_to?(m) } return result.invalid(errors: "missing methods: #{missing_methods.join(', ')}") if missing_methods.any? result end |
#of(*args) ⇒ Object Also known as: []
16 17 18 19 20 21 22 23 |
# File 'lib/plumb/interface_class.rb', line 16 def of(*args) case args in Array => symbols if symbols.all? { |s| s.is_a?(::Symbol) } self.class.new(symbols) else raise ::ArgumentError, "unexpected value to Types::Interface#of #{args.inspect}" end end |