Class: PgShrink::SubTableOperator
- Inherits:
-
Object
- Object
- PgShrink::SubTableOperator
show all
- Defined in:
- lib/pg_shrink/sub_table_operator.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent, table_name, opts = {}) ⇒ SubTableOperator
Returns a new instance of SubTableOperator.
20
21
22
23
24
25
26
27
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 20
def initialize(parent, table_name, opts = {})
self.parent = parent
self.table_name = table_name
self.database = parent.database
@opts = default_opts.merge(opts)
validate_opts!(@opts)
end
|
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
3
4
5
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 3
def database
@database
end
|
#parent ⇒ Object
Returns the value of attribute parent.
3
4
5
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 3
def parent
@parent
end
|
#table_name ⇒ Object
Returns the value of attribute table_name.
3
4
5
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 3
def table_name
@table_name
end
|
Instance Method Details
#default_opts ⇒ Object
4
5
6
7
8
9
10
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 4
def default_opts
{
:foreign_key =>
"#{ActiveSupport::Inflector.singularize(parent.table_name.to_s)}_id",
:primary_key => :id
}
end
|
#name ⇒ Object
12
13
14
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 12
def name
"#{table_name} #{self.class.name.demodulize} from #{parent.table_name}"
end
|
#propagate!(old_parent_data, new_parent_data) ⇒ Object
31
32
33
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 31
def propagate!(old_parent_data, new_parent_data)
raise "Implement in subclass"
end
|
#table ⇒ Object
16
17
18
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 16
def table
database.table(table_name)
end
|
#validate_opts!(opts) ⇒ Object
29
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 29
def validate_opts!(opts); end
|