Class: Plumb::Policy
Overview
Wrap a policy composition ("step") in a Policy object. So that visitors such as JSONSchema and Metadata visitors can define dedicated handlers for policies, if they need to.
Instance Attribute Summary collapse
-
#arg ⇒ Object
readonly
Returns the value of attribute arg.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#policy_name ⇒ Object
readonly
Returns the value of attribute policy_name.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Policy equality includes the wrapped step; otherwise same-named policies on disjoint types would compare equal and one could be reduced away.
-
#call(result) ⇒ Result
The standard Step interface.
-
#initialize(policy_name, arg, step) ⇒ Policy
constructor
A new instance of Policy.
-
#input_type ⇒ Object
A Policy is a transparent wrapper: it delegates type-flow to the wrapped step.
- #output_type ⇒ Object
- #with_children(children) ⇒ Object
Methods included from Composable
#&, #/, #>>, #[], #absorb_input, #absorb_output, #accepted_type, #as_node, #build, #check, #defer, #fusable_step?, #fuse_with, #generate, #idempotent?, included, #invalid, #invoke, #match, #metadata, #not, #pipeline, #policy, resolve_operand, #static, #subtype_identity, #to_json_schema, #to_mermaid, #to_plumb_type, #to_s, #transform, #value, #value_preserving?, #where, #with, wrap, #|
Methods included from Callable
Constructor Details
#initialize(policy_name, arg, step) ⇒ Policy
Returns a new instance of Policy.
20 21 22 23 24 25 26 |
# File 'lib/plumb/policy.rb', line 20 def initialize(policy_name, arg, step) @policy_name = policy_name @arg = arg @step = step @children = [step].freeze freeze end |
Instance Attribute Details
#arg ⇒ Object (readonly)
Returns the value of attribute arg.
12 13 14 |
# File 'lib/plumb/policy.rb', line 12 def arg @arg end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
12 13 14 |
# File 'lib/plumb/policy.rb', line 12 def children @children end |
#policy_name ⇒ Object (readonly)
Returns the value of attribute policy_name.
12 13 14 |
# File 'lib/plumb/policy.rb', line 12 def policy_name @policy_name end |
Instance Method Details
#==(other) ⇒ Boolean
Policy equality includes the wrapped step; otherwise same-named policies on disjoint types would compare equal and one could be reduced away.
32 33 34 35 36 37 |
# File 'lib/plumb/policy.rb', line 32 def ==(other) other.instance_of?(self.class) && policy_name == other.policy_name && arg == other.arg && children == other.children end |
#call(result) ⇒ Result
The standard Step interface.
47 |
# File 'lib/plumb/policy.rb', line 47 def call(result) = @step.call(result) |
#input_type ⇒ Object
A Policy is a transparent wrapper: it delegates type-flow to the wrapped step.
41 |
# File 'lib/plumb/policy.rb', line 41 def input_type = @step.input_type |
#output_type ⇒ Object
42 |
# File 'lib/plumb/policy.rb', line 42 def output_type = @step.output_type |
#with_children(children) ⇒ Object
18 |
# File 'lib/plumb/policy.rb', line 18 def with_children(children) = self.class.new(policy_name, arg, children.first) |