Class: JSON::SchemaDsl::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/json/schema_dsl/renderer.rb

Overview

Main entry point for the rendering chain of JSON::SchemaDsl.

This will in turn apply the registered renderers one by one, updating the entity-tree to result in json-schema.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity, scope = nil) ⇒ Renderer

Returns a new instance of Renderer.

Parameters:

  • entity (Entity)

    The root entity-tree of this render run.

  • scope (Object) (defaults to: nil)

    Used as a fallback for renderers that need access to helper methods.



19
20
21
22
# File 'lib/json/schema_dsl/renderer.rb', line 19

def initialize(entity, scope = nil)
  @entity = entity.to_h
  @scope = scope
end

Instance Attribute Details

#entityObject (readonly)

Returns the value of attribute entity.



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

def entity
  @entity
end

#scopeObject (readonly)

Returns the value of attribute scope.



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

def scope
  @scope
end

Class Method Details

.render(entity) ⇒ Object

See Also:



25
26
27
# File 'lib/json/schema_dsl/renderer.rb', line 25

def self.render(entity)
  new(entity).render
end

Instance Method Details

#renderHash

Applies the renderer chain in turn to produce valid json-schema. Each renderer traverses the whole tree before passing the resulting structure to the next renderer

Returns:

  • (Hash)

    The resulting json schema structure after each render is applied.



33
34
35
36
37
# File 'lib/json/schema_dsl/renderer.rb', line 33

def render
  render_chain.inject(entity) do |structure, renderer|
    renderer.new(scope).visit(structure)
  end
end