Class: PartialKs::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/partial_ks/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name) ⇒ Table

Returns a new instance of Table.



5
6
7
# File 'lib/partial_ks/table.rb', line 5

def initialize(table_name)
  @table_name = table_name
end

Instance Attribute Details

#table_nameObject (readonly)

Returns the value of attribute table_name.



3
4
5
# File 'lib/partial_ks/table.rb', line 3

def table_name
  @table_name
end

Instance Method Details

#modelObject



9
10
11
12
13
# File 'lib/partial_ks/table.rb', line 9

def model
  @model ||= table_name.classify.constantize
rescue NameError
  nil
end

#model?Boolean

sometimes the table is present, but the model is not defined e.g. in market specific tables

Returns:

  • (Boolean)


17
18
19
# File 'lib/partial_ks/table.rb', line 17

def model?
  model && model.respond_to?(:table_name)
end

#non_nullable_parent_tablesObject



25
26
27
# File 'lib/partial_ks/table.rb', line 25

def non_nullable_parent_tables
  non_nullable_reflections.map(&:plural_name)
end

#parent_tablesObject



29
30
31
# File 'lib/partial_ks/table.rb', line 29

def parent_tables
  belongs_to_reflections.map(&:plural_name)
end

#top_level_table?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/partial_ks/table.rb', line 21

def top_level_table?
  non_nullable_reflections.empty?
end