Class: JSON::SchemaDsl::Renderer
- Inherits:
-
Object
- Object
- JSON::SchemaDsl::Renderer
- 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
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(entity, scope = nil) ⇒ Renderer
constructor
A new instance of Renderer.
-
#render ⇒ Hash
Applies the renderer chain in turn to produce valid json-schema.
Constructor Details
#initialize(entity, scope = nil) ⇒ Renderer
Returns a new instance of Renderer.
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
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
14 15 16 |
# File 'lib/json/schema_dsl/renderer.rb', line 14 def entity @entity end |
#scope ⇒ Object (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
25 26 27 |
# File 'lib/json/schema_dsl/renderer.rb', line 25 def self.render(entity) new(entity).render end |
Instance Method Details
#render ⇒ Hash
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
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 |