Class: DumpTruck::SchemaConfiguration
- Inherits:
-
Object
- Object
- DumpTruck::SchemaConfiguration
- Defined in:
- lib/dump_truck/schema_configuration.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name) ⇒ SchemaConfiguration
constructor
A new instance of SchemaConfiguration.
- #table(name, &block) ⇒ Object
- #table_config_for(table) ⇒ Object
- #table_default ⇒ Object
- #tables ⇒ Object
- #target ⇒ Object
- #target_name ⇒ Object
- #target_path(target_path = nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ SchemaConfiguration
Returns a new instance of SchemaConfiguration.
5 6 7 8 9 10 11 12 |
# File 'lib/dump_truck/schema_configuration.rb', line 5 def initialize(name) @name = name @tables = Hash.new(TableConfiguration.new{truncate}) @target_path = 'tmp' @target_name_generator = proc{|schema| schema} instance_eval(&Proc.new) if block_given? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/dump_truck/schema_configuration.rb', line 3 def name @name end |
Instance Method Details
#==(other) ⇒ Object
47 48 49 |
# File 'lib/dump_truck/schema_configuration.rb', line 47 def ==(other) name == other.name && target_path == other.target_path && tables == other.tables end |
#table(name, &block) ⇒ Object
34 35 36 37 |
# File 'lib/dump_truck/schema_configuration.rb', line 34 def table(name, &block) name = name.to_s @tables[name] = TableConfiguration.new(name, &block) end |
#table_config_for(table) ⇒ Object
43 44 45 |
# File 'lib/dump_truck/schema_configuration.rb', line 43 def table_config_for(table) @tables[table.to_s] end |
#table_default ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/dump_truck/schema_configuration.rb', line 26 def table_default if block_given? @tables.default = TableConfiguration.new(&Proc.new) else @tables.default end end |
#tables ⇒ Object
39 40 41 |
# File 'lib/dump_truck/schema_configuration.rb', line 39 def tables @tables.values end |
#target ⇒ Object
22 23 24 |
# File 'lib/dump_truck/schema_configuration.rb', line 22 def target File.join(@target_path, @target_name_generator.call(@name) + '.sql.gz') end |
#target_name ⇒ Object
18 19 20 |
# File 'lib/dump_truck/schema_configuration.rb', line 18 def target_name @target_name_generator = Proc.new end |
#target_path(target_path = nil) ⇒ Object
14 15 16 |
# File 'lib/dump_truck/schema_configuration.rb', line 14 def target_path(target_path = nil) @target_path = target_path || @target_path end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/dump_truck/schema_configuration.rb', line 51 def to_s "<DumpTruck::SchemaConfiguration(#{name}) target:#{target} (#{tables.map(&:to_s).join(', ')})>" end |