Class: TableRenamable::DeprecatedTable
- Inherits:
-
Object
- Object
- TableRenamable::DeprecatedTable
- Defined in:
- lib/table_renamable/deprecated_table.rb
Overview
Class that handles the renaming of tables. This sets the table name of the class based on whether or not the table exists in the database
Defined Under Namespace
Classes: NoTableError
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#new_name ⇒ Object
Returns the value of attribute new_name.
-
#old_name ⇒ Object
Returns the value of attribute old_name.
Instance Method Summary collapse
-
#get_current_table_name ⇒ String
Returns the name of the table that currently exists of our two options (old or new).
-
#has_table?(table_name) ⇒ Boolean
Is this table name part of our DeprecatedTable definition.
-
#initialize(klass, old_name, new_name) ⇒ DeprecatedTable
constructor
Constructor - sets up the record and tries to connect to the correct database.
-
#set_table_name ⇒ Boolean
Set the correct table name for the Class we are controlling.
Constructor Details
#initialize(klass, old_name, new_name) ⇒ DeprecatedTable
Constructor - sets up the record and tries to connect to the correct database
32 33 34 35 36 37 38 |
# File 'lib/table_renamable/deprecated_table.rb', line 32 def initialize(klass, old_name, new_name) @klass = klass @old_name = old_name @new_name = new_name # call to set the correct table name self.set_table_name end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
14 15 16 |
# File 'lib/table_renamable/deprecated_table.rb', line 14 def klass @klass end |
#new_name ⇒ Object
Returns the value of attribute new_name.
22 23 24 |
# File 'lib/table_renamable/deprecated_table.rb', line 22 def new_name @new_name end |
#old_name ⇒ Object
Returns the value of attribute old_name.
18 19 20 |
# File 'lib/table_renamable/deprecated_table.rb', line 18 def old_name @old_name end |
Instance Method Details
#get_current_table_name ⇒ String
Returns the name of the table that currently exists of our two options (old or new)
45 46 47 48 49 50 51 |
# File 'lib/table_renamable/deprecated_table.rb', line 45 def get_current_table_name [self.old_name, self.new_name].each do |name| return name.to_s if self.table_exists?(name) end # raise exception if we don't have a valid table self.raise_no_table_error end |
#has_table?(table_name) ⇒ Boolean
Is this table name part of our DeprecatedTable definition
58 59 60 |
# File 'lib/table_renamable/deprecated_table.rb', line 58 def has_table?(table_name) [self.old_name, self.new_name].include?(table_name.to_sym) end |
#set_table_name ⇒ Boolean
Set the correct table name for the Class we are controlling
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/table_renamable/deprecated_table.rb', line 68 def set_table_name [self.old_name, self.new_name].each do |name| # make sure this table exists if self.table_exists?(name) # return true if we are already using this table return true if self.klass.table_name == name.to_s # otherwise we can change the table name self.klass.table_name = name return true end end self.raise_no_table_error end |