Module: JSON::SchemaDsl::AstNode

Included in:
Entity
Defined in:
lib/json/schema_dsl/ast_node.rb

Overview

Methods for an object to be used as an ast node by the renderer Include this module to define your own types that are not descendants of Entity. You should still implement two methods to be compatible with the normal builder class:

#initialize: Hash -> Self #to_h: Self -> Hash .has_attribute?: Symbol -> Boolean

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



14
15
16
# File 'lib/json/schema_dsl/ast_node.rb', line 14

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#renderObject

Used to do a simple render of the entity. Since this has no sensible scope while

rendering, use Builder#render instead.

See Also:



29
30
31
# File 'lib/json/schema_dsl/ast_node.rb', line 29

def render
  ::JSON::SchemaDsl::Renderer.new(self).render
end

#update(attribute_name, value = nil) ⇒ Entity

Returns Since entities themselves are immutable, this method returns a new entity with the attribute_name and value pair added.

Parameters:

  • attribute_name (Symbol)

    The name of the attribute to update.

  • value (Object) (defaults to: nil)

    The value that will be set for the attribute.

Returns:

  • (Entity)

    Since entities themselves are immutable, this method returns a new entity with the attribute_name and value pair added.



22
23
24
# File 'lib/json/schema_dsl/ast_node.rb', line 22

def update(attribute_name, value = nil)
  self.class.new(to_h.merge(attribute_name => value))
end