Class: Dart::Reflection::SequelTable::Resolver

Inherits:
AbstractResolver show all
Defined in:
lib/dart/reflection/sequel_table/resolver.rb

Defined Under Namespace

Classes: TheSchema

Instance Method Summary collapse

Constructor Details

#initialize(table_name) ⇒ Resolver

Returns a new instance of Resolver.



9
10
11
12
# File 'lib/dart/reflection/sequel_table/resolver.rb', line 9

def initialize(table_name)
  @table_name = table_name
  @relation   = TheSchema.instance.relation_for(table_name)
end

Instance Method Details

#association_for(ass_name) ⇒ Association

Returns the association with the given ass_name or nil if one does not exist

Parameters:

  • ass_name (String)

Returns:



22
23
24
25
26
# File 'lib/dart/reflection/sequel_table/resolver.rb', line 22

def association_for(ass_name)
  ass = relation.all_associations.detect { |ass| ass.name == ass_name }
  ass.scope = {} # no scope can be determined by SQL reflection
  ass
end

#build_from_association(association) ⇒ Object



14
15
16
# File 'lib/dart/reflection/sequel_table/resolver.rb', line 14

def build_from_association(association)
  self.class.new(association.associated_table)
end

#column_for(col_name) ⇒ String

Returns the column with the given col_name or nil if one does not exist

Parameters:

  • col_name (String)

Returns:

  • (String)


31
32
33
# File 'lib/dart/reflection/sequel_table/resolver.rb', line 31

def column_for(col_name)
  relation.column_names.detect { |col| col == col_name }
end

#table_nameObject



35
36
37
# File 'lib/dart/reflection/sequel_table/resolver.rb', line 35

def table_name
  @table_name
end