Class: DataImp::Porter
- Inherits:
-
Object
show all
- Defined in:
- lib/data_imp/porter.rb
Defined Under Namespace
Classes: Sample
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash, index = nil) ⇒ Porter
Returns a new instance of Porter.
23
24
25
26
|
# File 'lib/data_imp/porter.rb', line 23
def initialize(hash, index = nil)
@hash = HashWithIndifferentAccess.new(hash)
@index = index
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *_args) ⇒ Object
32
33
34
35
36
|
# File 'lib/data_imp/porter.rb', line 32
def method_missing(method, *_args)
return nil unless respond_to_missing?(method)
value = hash[method]
parse(method,value)
end
|
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
4
5
6
|
# File 'lib/data_imp/porter.rb', line 4
def hash
@hash
end
|
#index ⇒ Object
Returns the value of attribute index.
4
5
6
|
# File 'lib/data_imp/porter.rb', line 4
def index
@index
end
|
Class Method Details
.after_all_imports ⇒ Object
59
60
61
|
# File 'lib/data_imp/porter.rb', line 59
def self.after_all_imports
end
|
.before_all_imports ⇒ Object
42
43
44
|
# File 'lib/data_imp/porter.rb', line 42
def self.before_all_imports
end
|
.find_importer(type) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/data_imp/porter.rb', line 7
def find_importer type
return type if type.kind_of? DataImp::Porter
return self if type.blank?
begin
type = type.to_s.camelize
const_get type
rescue NameError => e
if require_relative "porter/#{type.underscore}"
retry
end
end
rescue LoadError => e
raise DataImp::NoImporter.new(type)
end
|
Instance Method Details
#after_import ⇒ Object
55
56
57
|
# File 'lib/data_imp/porter.rb', line 55
def after_import
end
|
#before_import ⇒ Object
46
47
48
|
# File 'lib/data_imp/porter.rb', line 46
def before_import
end
|
#import ⇒ Object
50
51
52
53
|
# File 'lib/data_imp/porter.rb', line 50
def import
warn "Import: #{self.class.name}:#{index}:#{hash.inspect}"
end
|
#on_error(e) ⇒ Object
63
64
65
66
|
# File 'lib/data_imp/porter.rb', line 63
def on_error e
warn "Error: #{self.class.name}:#{index}:#{hash.inspect}"
warn e
end
|
#parse(method, value) ⇒ Object
38
39
40
|
# File 'lib/data_imp/porter.rb', line 38
def parse method, value
value end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
28
29
30
|
# File 'lib/data_imp/porter.rb', line 28
def respond_to_missing?(method, include_private = false)
hash.has_key?(method) || false end
|