Class: RomSqlGraph::Edges

Inherits:
Object
  • Object
show all
Defined in:
lib/rom_sql_graph/edges.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Edges

Returns a new instance of Edges.



5
6
7
# File 'lib/rom_sql_graph/edges.rb', line 5

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

Instance Attribute Details

#relationsObject (readonly)

Returns the value of attribute relations.



3
4
5
# File 'lib/rom_sql_graph/edges.rb', line 3

def relations
  @relations
end

Instance Method Details

#to_aObject



9
10
11
12
13
14
15
16
# File 'lib/rom_sql_graph/edges.rb', line 9

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