Class: Plumb::Composable::Node

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

Overview

 Support #as_node.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#parse, #resolve

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

#argsObject (readonly)

Returns the value of attribute args.



276
277
278
# File 'lib/plumb/composable.rb', line 276

def args
  @args
end

#node_nameObject (readonly)

Returns the value of attribute node_name.



276
277
278
# File 'lib/plumb/composable.rb', line 276

def node_name
  @node_name
end

#typeObject (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