Class: Plumb::Policy

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/plumb/policy.rb

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

Instance Method Summary collapse

Methods included from Composable

#>>, #[], #as_node, #build, #check, #defer, #generate, included, #invalid, #invoke, #match, #metadata, #not, #pipeline, #policy, #static, #to_json_schema, #to_s, #transform, #value, wrap, #|

Methods included from Callable

#parse, #resolve

Constructor Details

#initialize(policy_name, arg, step) ⇒ Policy

Returns a new instance of Policy.

Parameters:

  • policy_name (Symbol)
  • arg (Object, nil)

    the argument to the policy, if any.

  • step (Step)

    the step composition wrapped by this policy.



17
18
19
20
21
22
23
# File 'lib/plumb/policy.rb', line 17

def initialize(policy_name, arg, step)
  @policy_name = policy_name
  @arg = arg
  @step = step
  @children = [step].freeze
  freeze
end

Instance Attribute Details

#argObject (readonly)

Returns the value of attribute arg.



12
13
14
# File 'lib/plumb/policy.rb', line 12

def arg
  @arg
end

#childrenObject (readonly)

Returns the value of attribute children.



12
13
14
# File 'lib/plumb/policy.rb', line 12

def children
  @children
end

#policy_nameObject (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) ⇒ Object



25
26
27
28
29
# File 'lib/plumb/policy.rb', line 25

def ==(other)
  other.is_a?(self.class) &&
    policy_name == other.policy_name &&
    arg == other.arg
end

#call(result) ⇒ Result::Valid, Result::Invalid

The standard Step interface.

Parameters:

Returns:



34
# File 'lib/plumb/policy.rb', line 34

def call(result) = @step.call(result)