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) ⇒ Object
Apply limit clause to source, return new source.
-
#handle_offset(source) ⇒ Object
Apply offset clause to source, return new source.
-
#handle_order(source) ⇒ Object
Apply order clause to source, return new source.
-
#handle_where(source) ⇒ 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.
-
#to_query(source) ⇒ Object
Constructs the query, if applicable.
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.
84 85 86 |
# File 'lib/migratrix/extractions/extraction.rb', line 84 def execute_extract(source, ={}) raise NotImplementedError end |
#extract(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/migratrix/extractions/extraction.rb', line 17 def extract(={}) = @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 = handle_where(src, [:where]) if [:where] src = handle_order(src, [:order]) if [:order] src = handle_limit(src, [:limit]) if [:limit] src = handle_offset(src, [:offset]) if [:offset] execute_extract(src, ) end |
#handle_limit(source) ⇒ Object
Apply limit clause to source, return new source.
63 64 65 |
# File 'lib/migratrix/extractions/extraction.rb', line 63 def handle_limit(source) raise NotImplementedError end |
#handle_offset(source) ⇒ Object
Apply offset clause to source, return new source.
68 69 70 |
# File 'lib/migratrix/extractions/extraction.rb', line 68 def handle_offset(source) raise NotImplementedError end |
#handle_order(source) ⇒ Object
Apply order clause to source, return new source.
73 74 75 |
# File 'lib/migratrix/extractions/extraction.rb', line 73 def handle_order(source) raise NotImplementedError end |
#handle_where(source) ⇒ Object
Apply where clause to source, return new source.
58 59 60 |
# File 'lib/migratrix/extractions/extraction.rb', line 58 def handle_where(source) 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.
53 54 55 |
# File 'lib/migratrix/extractions/extraction.rb', line 53 def obtain_source(source, ={}) raise NotImplementedError end |
#to_query(source) ⇒ Object
Constructs the query, if applicable. May not exist or make sense for non-SQL and/or non-ActiveRecord extractions.
79 80 81 |
# File 'lib/migratrix/extractions/extraction.rb', line 79 def to_query(source) raise NotImplementedError end |