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.
28
29
30
31
32
33
34
35
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 28
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
|
# 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
11
12
13
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 11
def name
"#{table_name} #{self.class.name.demodulize} from #{parent.table_name}"
end
|
#propagate!(old_parent_data, new_parent_data) ⇒ Object
37
38
39
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 37
def propagate!(old_parent_data, new_parent_data)
raise "Implement in subclass"
end
|
#table ⇒ Object
15
16
17
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 15
def table
database.table(table_name)
end
|
#validate_opts!(opts) ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/pg_shrink/sub_table_operator.rb', line 19
def validate_opts!(opts)
if opts[:type_key] && !opts[:type]
raise "Error: #{name} has type_key set but no type"
end
if opts[:type] && !opts[:type_key]
raise "Error: #{name} has type set but no type_key"
end
end
|