Class: Render::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/render/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  self.schema = determine_schema(schema_or_definition)
  self.relationships = (options.delete(:relationships) || {})
  self.graphs = (options.delete(:graphs) || [])
  self.raw_endpoint = (options.delete(:endpoint) || schema.definition[:endpoint]).to_s
  self.config = options
  self.relationship_info = {}
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



9
10
11
# File 'lib/render/graph.rb', line 9

def config
  @config
end

#graphsObject

Returns the value of attribute graphs.



9
10
11
# File 'lib/render/graph.rb', line 9

def graphs
  @graphs
end

#raw_endpointObject

Returns the value of attribute raw_endpoint.



9
10
11
# File 'lib/render/graph.rb', line 9

def raw_endpoint
  @raw_endpoint
end

#relationship_infoObject

Returns the value of attribute relationship_info.



9
10
11
# File 'lib/render/graph.rb', line 9

def relationship_info
  @relationship_info
end

#relationshipsObject

Returns the value of attribute relationships.



9
10
11
# File 'lib/render/graph.rb', line 9

def relationships
  @relationships
end

#rendered_dataObject

Returns the value of attribute rendered_data.



9
10
11
# File 'lib/render/graph.rb', line 9

def rendered_data
  @rendered_data
end

#schemaObject

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

#titleObject



26
27
28
# File 'lib/render/graph.rb', line 26

def title
  schema.id || schema.title
end