Class: PartialKs::Table
- Inherits:
-
Object
- Object
- PartialKs::Table
- Defined in:
- lib/partial_ks/table.rb
Instance Attribute Summary collapse
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
-
#initialize(table_name) ⇒ Table
constructor
A new instance of Table.
- #model ⇒ Object
-
#model? ⇒ Boolean
sometimes the table is present, but the model is not defined e.g.
- #non_nullable_parent_tables ⇒ Object
- #parent_tables ⇒ Object
- #top_level_table? ⇒ Boolean
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_name ⇒ Object (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
#model ⇒ Object
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
17 18 19 |
# File 'lib/partial_ks/table.rb', line 17 def model? model && model.respond_to?(:table_name) end |
#non_nullable_parent_tables ⇒ Object
25 26 27 |
# File 'lib/partial_ks/table.rb', line 25 def non_nullable_parent_tables non_nullable_reflections.map(&:plural_name) end |
#parent_tables ⇒ Object
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
21 22 23 |
# File 'lib/partial_ks/table.rb', line 21 def top_level_table? non_nullable_reflections.empty? end |