Class: DataImport::Dsl::Import
- Inherits:
-
Object
- Object
- DataImport::Dsl::Import
- Defined in:
- lib/data-import/dsl/import.rb,
lib/data-import/dsl/import/from.rb
Defined Under Namespace
Classes: From
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #after_row(&block) ⇒ Object
- #dependencies(*dependencies) ⇒ Object
- #from(name = nil, options = {}, &block) ⇒ Object
-
#initialize(definition) ⇒ Import
constructor
A new instance of Import.
- #mapping(*hash_or_symbols, &block) ⇒ Object
- #to(name, options = {}) ⇒ Object
Constructor Details
#initialize(definition) ⇒ Import
Returns a new instance of Import.
6 7 8 |
# File 'lib/data-import/dsl/import.rb', line 6 def initialize(definition) @definition = definition end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
4 5 6 |
# File 'lib/data-import/dsl/import.rb', line 4 def definition @definition end |
Instance Method Details
#after(&block) ⇒ Object
32 33 34 |
# File 'lib/data-import/dsl/import.rb', line 32 def after(&block) definition.after_blocks << block end |
#after_row(&block) ⇒ Object
36 37 38 |
# File 'lib/data-import/dsl/import.rb', line 36 def after_row(&block) definition.after_row_blocks << block end |
#dependencies(*dependencies) ⇒ Object
40 41 42 43 44 |
# File 'lib/data-import/dsl/import.rb', line 40 def dependencies(*dependencies) dependencies.each do |dependency| definition.add_dependency(dependency) end end |
#from(name = nil, options = {}, &block) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/data-import/dsl/import.rb', line 10 def from(name = nil, = {}, &block) definition.source_table_name = name definition.source_primary_key = [:primary_key] From.new(definition).instance_eval &block if block_given? end |
#mapping(*hash_or_symbols, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/data-import/dsl/import.rb', line 22 def mapping(*hash_or_symbols, &block) if hash_or_symbols.first.is_a? Hash definition.mappings.merge! hash_or_symbols.first else symbols = hash_or_symbols symbols = symbols.first if symbols.count == 1 definition.mappings[symbols] = block end end |
#to(name, options = {}) ⇒ Object
17 18 19 20 |
# File 'lib/data-import/dsl/import.rb', line 17 def to(name, = {}) definition.target_table_name = name definition.use_mode(:update) if [:mode] == :update end |