Sha256: 841af11a71647d58280a96fbf8019a0e49eefa12cd5a33e01e5108cdaf57e9c7

Contents?: true

Size: 881 Bytes

Versions: 3

Compression:

Stored size: 881 Bytes

Contents

module Rasti
  module DB
    module Relations
      class GraphBuilder
        class << self

          def graph_to(rows, relations, collection_class, db, schema=nil)
            return if rows.empty?

            parse(relations).each do |relation, nested_relations|
              raise "Undefined relation #{relation} for #{collection_class}" unless collection_class.relations.key? relation
              collection_class.relations[relation].graph_to rows, db, schema, nested_relations
            end
          end

          private

          def parse(relations)
            relations.each_with_object({}) do |relation, hash|
              tail = relation.to_s.split '.'
              head = tail.shift.to_sym
              hash[head] ||= []
              hash[head] << tail.join('.') unless tail.empty?
            end
          end

        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rasti-db-1.0.0 lib/rasti/db/relations/graph_builder.rb
rasti-db-0.4.1 lib/rasti/db/relations/graph_builder.rb
rasti-db-0.4.0 lib/rasti/db/relations/graph_builder.rb