lib/render/graph.rb in render-0.0.1 vs lib/render/graph.rb in render-0.0.2

- old
+ new

@@ -4,10 +4,11 @@ # - Config for this endpoint, e.g. an access token # - Relationships between it and a Graph that includes it require "render/schema" require "render/errors" +require "render/dottable_hash" module Render class Graph PARAM = %r{:(?<param>[\w_]+)} PARAMS = %r{#{PARAM}[\/\;\&]?} @@ -52,33 +53,34 @@ end uri.to_s end - def pull(inherited_attributes = {}) + def render(inherited_attributes = {}) calculate_parental_params!(inherited_attributes) - graph_attributes = schema.pull(inherited_attributes.merge(parental_params.merge({ endpoint: endpoint }))) + graph_attributes = schema.render(inherited_attributes.merge(parental_params.merge({ endpoint: endpoint }))) - graphs.inject(graph_attributes) do |attributes, nested_graph| + graph = graphs.inject(graph_attributes) do |attributes, nested_graph| threads = [] # TODO threading should be configured so people may also think about Thread.abort_on_transaction! threads << Thread.new do title = schema.title.to_sym parent_data = attributes[title] nested_graph_data = if parent_data.is_a?(Array) data = parent_data.collect do |element| - nested_graph.pull(element) + nested_graph.render(element) end key = data.first.keys.first attributes[title] = data.collect { |d| d[key] } else - data = nested_graph.pull(parent_data) + data = nested_graph.render(parent_data) parent_data.merge!(data) end end threads.collect(&:join) - DottableHash.new(attributes) + attributes end + DottableHash.new(graph) end private def initialize_params!