Class: Migratrix::Extractions::Extraction
- Includes:
- Loggable, ValidOptions
- Defined in:
- lib/migratrix/extractions/extraction.rb
Overview
base class for extraction
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
-
#execute_extract(source, options = {}) ⇒ Object
Execute the extraction and return the result set.
- #extract(options = {}) ⇒ Object
-
#handle_limit(source, limit) ⇒ Object
Apply limit clause to source, return new source.
-
#handle_offset(source, offset) ⇒ Object
Apply offset clause to source, return new source.
-
#handle_order(source, order) ⇒ Object
Apply order clause to source, return new source.
-
#handle_where(source, where) ⇒ Object
Apply where clause to source, return new source.
-
#initialize(name, options = {}) ⇒ Extraction
constructor
A new instance of Extraction.
-
#obtain_source(source, options = {}) ⇒ Object
First step in extraction is to take the given source and turn it into something that the filter chain can used.
- #process_source(source, options) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Extraction
Returns a new instance of Extraction.
12 13 14 15 |
# File 'lib/migratrix/extractions/extraction.rb', line 12 def initialize(name, ={}) @options = .deep_copy self.source = [:source] if [:source] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/migratrix/extractions/extraction.rb', line 8 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/migratrix/extractions/extraction.rb', line 8 def @options end |
#source ⇒ Object
Returns the value of attribute source.
8 9 10 |
# File 'lib/migratrix/extractions/extraction.rb', line 8 def source @source end |
Instance Method Details
#execute_extract(source, options = {}) ⇒ Object
Execute the extraction and return the result set.
88 89 90 |
# File 'lib/migratrix/extractions/extraction.rb', line 88 def execute_extract(source, ={}) raise NotImplementedError end |
#extract(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/migratrix/extractions/extraction.rb', line 17 def extract(={}) = .deep_copy [:where] = Array([:where]) + Array(@options[:where]) = @options.merge().symbolize_keys # TODO: Raise error if self.abstract? DANGER/NOTE that this is # the "default strategy" for extraction, and may need to be # extracted to a strategy object. src = obtain_source(self.source, ) src = process_source(src, ) execute_extract(src, ) end |
#handle_limit(source, limit) ⇒ Object
Apply limit clause to source, return new source.
73 74 75 |
# File 'lib/migratrix/extractions/extraction.rb', line 73 def handle_limit(source, limit) raise NotImplementedError end |
#handle_offset(source, offset) ⇒ Object
Apply offset clause to source, return new source.
78 79 80 |
# File 'lib/migratrix/extractions/extraction.rb', line 78 def handle_offset(source, offset) raise NotImplementedError end |
#handle_order(source, order) ⇒ Object
Apply order clause to source, return new source.
83 84 85 |
# File 'lib/migratrix/extractions/extraction.rb', line 83 def handle_order(source, order) raise NotImplementedError end |
#handle_where(source, where) ⇒ Object
Apply where clause to source, return new source.
68 69 70 |
# File 'lib/migratrix/extractions/extraction.rb', line 68 def handle_where(source, where) raise NotImplementedError end |
#obtain_source(source, options = {}) ⇒ Object
First step in extraction is to take the given source and turn it into something that the filter chain can used. The ActiveRecord extraction uses a legacy model class as its source so it can simply return its source. A CSV or Yaml extraction here might need to read the entire file contents and returns the full, unfiltered data source.
63 64 65 |
# File 'lib/migratrix/extractions/extraction.rb', line 63 def obtain_source(source, ={}) raise NotImplementedError end |
#process_source(source, options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/migratrix/extractions/extraction.rb', line 31 def process_source(source, ) if [:where] [:where].each do |where| source = handle_where(source, where) end end source = handle_order(source, [:order]) if [:order] source = handle_limit(source, [:limit]) if [:limit] source = handle_offset(source, [:offset]) if [:offset] source end |