Class: Render::Graph
- Inherits:
-
Object
- Object
- Render::Graph
- Defined in:
- lib/render/graph.rb
Constant Summary collapse
- PARAM =
%r{:(?<param>[\w_]+)}- PARAMS =
%r{#{PARAM}[\/\;\&]?}
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#graphs ⇒ Object
Returns the value of attribute graphs.
-
#inherited_data ⇒ Object
Returns the value of attribute inherited_data.
-
#raw_endpoint ⇒ Object
Returns the value of attribute raw_endpoint.
-
#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!(inherited_properties = nil) ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(schema_or_definition, options = {}) ⇒ Graph
Returns a new instance of Graph.
18 19 20 21 22 23 24 25 26 |
# File 'lib/render/graph.rb', line 18 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.inherited_data = {} end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/render/graph.rb', line 10 def config @config end |
#graphs ⇒ Object
Returns the value of attribute graphs.
10 11 12 |
# File 'lib/render/graph.rb', line 10 def graphs @graphs end |
#inherited_data ⇒ Object
Returns the value of attribute inherited_data.
10 11 12 |
# File 'lib/render/graph.rb', line 10 def inherited_data @inherited_data end |
#raw_endpoint ⇒ Object
Returns the value of attribute raw_endpoint.
10 11 12 |
# File 'lib/render/graph.rb', line 10 def raw_endpoint @raw_endpoint end |
#relationships ⇒ Object
Returns the value of attribute relationships.
10 11 12 |
# File 'lib/render/graph.rb', line 10 def relationships @relationships end |
#rendered_data ⇒ Object
Returns the value of attribute rendered_data.
10 11 12 |
# File 'lib/render/graph.rb', line 10 def rendered_data @rendered_data end |
#schema ⇒ Object
Returns the value of attribute schema.
10 11 12 |
# File 'lib/render/graph.rb', line 10 def schema @schema end |
Instance Method Details
#render!(inherited_properties = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/render/graph.rb', line 32 def render!(inherited_properties = nil) self.inherited_data = inherited_properties if (schema.type == Array) explicit_data = inherited_data else explicit_data = inherited_data.is_a?(Hash) ? inherited_data : {} explicit_data = explicit_data.merge!(relationship_data_from_parent) end graph_data = Extensions::DottableHash.new rendered_data = schema.render!(explicit_data, endpoint) do |parent_data| loop_with_configured_threading(graphs) do |graph| if parent_data.is_a?(Array) graph_data[graph.title] = parent_data.inject([]) do |nested_data, element| nested_data << graph.render!(element)[graph.title] end else nested_data = graph.render!(parent_data) graph_data.merge!(nested_data) end end end self.rendered_data = graph_data.merge!(rendered_data) end |
#title ⇒ Object
28 29 30 |
# File 'lib/render/graph.rb', line 28 def title schema.universal_title || schema.title end |