Class: Migratrix::Extractions::Extraction

Inherits:
Object
  • Object
show all
Includes:
Loggable, ValidOptions
Defined in:
lib/migratrix/extractions/extraction.rb

Overview

base class for extraction

Direct Known Subclasses

ActiveRecord

Instance Attribute Summary collapse

Instance Method Summary collapse

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={})
  @options = options.deep_copy
  self.source = options[:source] if options[:source]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/migratrix/extractions/extraction.rb', line 8

def name
  @name
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/migratrix/extractions/extraction.rb', line 8

def options
  @options
end

#sourceObject

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.

Raises:

  • (NotImplementedError)


84
85
86
# File 'lib/migratrix/extractions/extraction.rb', line 84

def execute_extract(source, options={})
  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={})
  options = @options.merge(options).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, options)
  src = handle_where(src, options[:where]) if options[:where]
  src = handle_order(src, options[:order]) if options[:order]
  src = handle_limit(src, options[:limit]) if options[:limit]
  src = handle_offset(src, options[:offset]) if options[:offset]
  execute_extract(src, options)
end

#handle_limit(source) ⇒ Object

Apply limit clause to source, return new source.

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/migratrix/extractions/extraction.rb', line 53

def obtain_source(source, options={})
  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.

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/migratrix/extractions/extraction.rb', line 79

def to_query(source)
  raise NotImplementedError
end