Sha256: e058a3634e97cf7814965fdc10a52bf181f84cb5341db87a659f653fc6c66de0

Contents?: true

Size: 639 Bytes

Versions: 2

Compression:

Stored size: 639 Bytes

Contents

module RomSqlGraph
  class Edges
    attr_reader :relations

    def initialize(repo)
      @relations = sql_relations(repo)
    end

    def to_a
      relations.map do |name, relation|
        relation.schema.associations.elements.map do |_, object|
          association_name = Inflecto.pluralize(object.target.to_sym.to_s).to_sym
          [name, association_name]
        end
      end.map! { |array| array.empty? ? nil : array }.compact.flatten(1)
    end

  private

    SQL = :sql

    def sql_relations(repo)
      repo.container.relations.elements
        .select { |name, object| object.class.adapter == SQL }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rom_sql_graph-0.2.0 lib/rom_sql_graph/edges.rb
rom_sql_graph-0.1.0 lib/rom_sql_graph/edges.rb