Class: Plumb::Composable::Node
- Inherits:
-
Object
- Object
- Plumb::Composable::Node
- Includes:
- Plumb::Composable
- Defined in:
- lib/plumb/composable.rb
Overview
Support #as_node.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#node_name ⇒ Object
readonly
Returns the value of attribute node_name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two nodes are equal when they wrap the same type with the same node_name and args.
- #call(result) ⇒ Object
-
#initialize(node_name, type, args = BLANK_HASH) ⇒ Node
constructor
A new instance of Node.
-
#metadata(data = Undefined) ⇒ Object
When wrapping a node in Metadata we need to preserte the Node with cistom node_name.
Methods included from Plumb::Composable
#>>, #[], #as_node, #build, #check, #children, #defer, #generate, included, #invalid, #invoke, #match, #not, #pipeline, #policy, #static, #to_json_schema, #to_s, #transform, #value, #where, #with, wrap, #|
Methods included from Plumb::Callable
Constructor Details
#initialize(node_name, type, args = BLANK_HASH) ⇒ Node
Returns a new instance of Node.
278 279 280 281 282 283 |
# File 'lib/plumb/composable.rb', line 278 def initialize(node_name, type, args = BLANK_HASH) @node_name = node_name @type = type @args = args freeze end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
276 277 278 |
# File 'lib/plumb/composable.rb', line 276 def args @args end |
#node_name ⇒ Object (readonly)
Returns the value of attribute node_name.
276 277 278 |
# File 'lib/plumb/composable.rb', line 276 def node_name @node_name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
276 277 278 |
# File 'lib/plumb/composable.rb', line 276 def type @type end |
Instance Method Details
#==(other) ⇒ Object
Two nodes are equal when they wrap the same type with the same node_name and args. The default Composable#== compares #children, but a Node holds its identity in @node_name/@type/@args, so without this every as_node-wrapped type (Email, Boolean, etc.) would compare equal to every other.
304 305 306 307 308 309 |
# File 'lib/plumb/composable.rb', line 304 def ==(other) other.is_a?(self.class) && other.node_name == node_name && other.type == type && other.args == args end |
#call(result) ⇒ Object
297 |
# File 'lib/plumb/composable.rb', line 297 def call(result) = type.call(result) |
#metadata(data = Undefined) ⇒ Object
When wrapping a node in Metadata we need to preserte the Node with cistom node_name. but when just querying metadata, we can delegate to the underlying type.
289 290 291 292 293 294 295 |
# File 'lib/plumb/composable.rb', line 289 def (data = Undefined) if data == Undefined type. else Metadata.new(self, data) end end |