Class: Render::Graph
- Inherits:
-
Object
- Object
- Render::Graph
- Defined in:
- lib/render/graph.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#graphs ⇒ Object
Returns the value of attribute graphs.
-
#raw_endpoint ⇒ Object
Returns the value of attribute raw_endpoint.
-
#relationship_info ⇒ Object
Returns the value of attribute relationship_info.
-
#relationships ⇒ Object
Returns the value of attribute relationships.
-
#rendered_data ⇒ Object
Returns the value of attribute rendered_data.
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(schema_or_definition, options = {}) ⇒ Graph
constructor
A new instance of Graph.
- #render!(explicit_data = nil, parental_data = nil, as_array = false) ⇒ Object
- #serialize!(explicit_data = nil, parental_data = nil) ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(schema_or_definition, options = {}) ⇒ Graph
Returns a new instance of Graph.
17 18 19 20 21 22 23 24 |
# File 'lib/render/graph.rb', line 17 def initialize(schema_or_definition, = {}) self.schema = determine_schema(schema_or_definition) self.relationships = (.delete(:relationships) || {}) self.graphs = (.delete(:graphs) || []) self.raw_endpoint = (.delete(:endpoint) || schema.definition[:endpoint]).to_s self.config = self.relationship_info = {} end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/render/graph.rb', line 9 def config @config end |
#graphs ⇒ Object
Returns the value of attribute graphs.
9 10 11 |
# File 'lib/render/graph.rb', line 9 def graphs @graphs end |
#raw_endpoint ⇒ Object
Returns the value of attribute raw_endpoint.
9 10 11 |
# File 'lib/render/graph.rb', line 9 def raw_endpoint @raw_endpoint end |
#relationship_info ⇒ Object
Returns the value of attribute relationship_info.
9 10 11 |
# File 'lib/render/graph.rb', line 9 def relationship_info @relationship_info end |
#relationships ⇒ Object
Returns the value of attribute relationships.
9 10 11 |
# File 'lib/render/graph.rb', line 9 def relationships @relationships end |
#rendered_data ⇒ Object
Returns the value of attribute rendered_data.
9 10 11 |
# File 'lib/render/graph.rb', line 9 def rendered_data @rendered_data end |
#schema ⇒ Object
Returns the value of attribute schema.
9 10 11 |
# File 'lib/render/graph.rb', line 9 def schema @schema end |
Instance Method Details
#render!(explicit_data = nil, parental_data = nil, as_array = false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/render/graph.rb', line 41 def render!(explicit_data = nil, parental_data = nil, as_array = false) if as_array data = parental_data.inject([]) do |accumulator, parental_element| accumulator << serialize!(explicit_data, parental_element) end else data = serialize!(explicit_data, parental_data) end loop_with_configured_threading(graphs) do |graph| graph.render!(explicit_data, data, (schema.type == Array)) end self.rendered_data = graphs.inject(Extensions::DottableHash.new) do |data, graph| data[graph.title] = graph.rendered_data end self.rendered_data[title] = data rendered_data end |
#serialize!(explicit_data = nil, parental_data = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/render/graph.rb', line 30 def serialize!(explicit_data = nil, parental_data = nil) process_relationship_info!(parental_data) if (schema.type == Array) schema.render!(explicit_data, endpoint) else explicit_data ||= {} schema.render!(explicit_data.merge(relationship_info), endpoint) end end |
#title ⇒ Object
26 27 28 |
# File 'lib/render/graph.rb', line 26 def title schema.id || schema.title end |