class JSON::SchemaDsl::Renderer

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.

Attributes

entity[R]
scope[R]

Public Class Methods

new(entity, scope = nil) click to toggle source

@param [Entity] entity The root entity-tree of this render run. @param [Object] scope Used as a fallback for renderers that need access

to helper methods.
# File lib/json/schema_dsl/renderer.rb, line 19
def initialize(entity, scope = nil)
  @entity = entity.to_h
  @scope = scope
end
render(entity) click to toggle source

@see render

# File lib/json/schema_dsl/renderer.rb, line 25
def self.render(entity)
  new(entity).render
end

Public Instance Methods

render() click to toggle source

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 @return [Hash] The resulting json schema structure after each render is applied.

# 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

Private Instance Methods

render_chain() click to toggle source

@return [Array<Class>] Each rendering class that will be applied to the given entity. @see ::JSON::SchemaDsl.registered_renderers

# File lib/json/schema_dsl/renderer.rb, line 43
def render_chain
  ::JSON::SchemaDsl.registered_renderers
end