Class: Jetel::Modules::Module
- Inherits:
-
Object
- Object
- Jetel::Modules::Module
show all
- Defined in:
- lib/jetel/modules/module.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.download_dir(modul, source, opts) ⇒ Object
-
.downloaded_file(modul, source, opts) ⇒ Object
-
.extract_dir(modul, source, opts) ⇒ Object
-
.extracted_file(modul, source, opts) ⇒ Object
-
.target_dir(modul, source, dir, *path) ⇒ Object
-
.transform_dir(modul, source, opts) ⇒ Object
-
.transformed_file(modul, source, opts) ⇒ Object
Instance Method Summary
collapse
-
#download_dir(source, opts) ⇒ Object
-
#download_source(source, opts) ⇒ Object
-
#downloaded_file(source, opts) ⇒ Object
-
#extract_dir(source, opts) ⇒ Object
-
#extracted_file(source, opts) ⇒ Object
-
#initialize ⇒ Module
constructor
A new instance of Module.
-
#load(global_options, options, args) ⇒ Object
-
#target_dir(source, opts, *path) ⇒ Object
-
#transform_dir(source, opts) ⇒ Object
-
#transformed_file(source, opts) ⇒ Object
-
#unzip(source, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Module
Returns a new instance of Module.
45
46
47
|
# File 'lib/jetel/modules/module.rb', line 45
def initialize
@downloader = Downloader.new
end
|
Instance Attribute Details
#downloader ⇒ Object
Returns the value of attribute downloader.
11
12
13
|
# File 'lib/jetel/modules/module.rb', line 11
def downloader
@downloader
end
|
Class Method Details
.download_dir(modul, source, opts) ⇒ Object
20
21
22
|
# File 'lib/jetel/modules/module.rb', line 20
def download_dir(modul, source, opts)
Module.target_dir(modul, source, opts, 'downloaded')
end
|
.downloaded_file(modul, source, opts) ⇒ Object
32
33
34
|
# File 'lib/jetel/modules/module.rb', line 32
def downloaded_file(modul, source, opts)
File.join(download_dir(modul, source, opts), source[:filename_downloaded] || source[:url].split('/').last)
end
|
24
25
26
|
# File 'lib/jetel/modules/module.rb', line 24
def (modul, source, opts)
Module.target_dir(modul, source, opts, 'extracted')
end
|
36
37
38
|
# File 'lib/jetel/modules/module.rb', line 36
def (modul, source, opts)
File.join((modul, source, opts), source[:filename_extracted] || source[:url].split('/').last)
end
|
.target_dir(modul, source, dir, *path) ⇒ Object
14
15
16
17
18
|
# File 'lib/jetel/modules/module.rb', line 14
def target_dir(modul, source, dir, *path)
klass = modul.class.name.split('::').last
source_name = Helper.sanitize(source[:name])
File.join(dir.kind_of?(String) ? dir : dir['download_dir'] || Config[:DATA_DIRECTORY], klass, source_name, path)
end
|
28
29
30
|
# File 'lib/jetel/modules/module.rb', line 28
def transform_dir(modul, source, opts)
Module.target_dir(modul, source, opts, 'transformed')
end
|
40
41
42
|
# File 'lib/jetel/modules/module.rb', line 40
def transformed_file(modul, source, opts)
File.join(transform_dir(modul, source, opts), source[:filename_transformed] || source[:url].split('/').last)
end
|
Instance Method Details
#download_dir(source, opts) ⇒ Object
57
58
59
|
# File 'lib/jetel/modules/module.rb', line 57
def download_dir(source, opts)
Module.download_dir(self, source, opts)
end
|
#download_source(source, opts) ⇒ Object
49
50
51
|
# File 'lib/jetel/modules/module.rb', line 49
def download_source(source, opts)
downloader.download(source[:url], {:dir => download_dir(source, opts), :filename => source[:filename_downloaded]})
end
|
#downloaded_file(source, opts) ⇒ Object
69
70
71
|
# File 'lib/jetel/modules/module.rb', line 69
def downloaded_file(source, opts)
Module.downloaded_file(self, source, opts)
end
|
61
62
63
|
# File 'lib/jetel/modules/module.rb', line 61
def (source, opts)
Module.(self, source, opts)
end
|
73
74
75
|
# File 'lib/jetel/modules/module.rb', line 73
def (source, opts)
Module.(self, source, opts)
end
|
#load(global_options, options, args) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/jetel/modules/module.rb', line 81
def load(global_options, options, args)
sources = self.class.sources
if args.length > 0
args = args.map(&:downcase)
sources = sources.select do |source|
args.index(source[:name].downcase)
end
end
sources.pmap(8) do |source|
opts = global_options.merge(options)
transformed_file = transformed_file(source, opts)
loader = Helper.get_loader(opts['data_loader'])
loader.load(self, source, transformed_file, opts)
end
end
|
#target_dir(source, opts, *path) ⇒ Object
53
54
55
|
# File 'lib/jetel/modules/module.rb', line 53
def target_dir(source, opts, *path)
Module.target_dir(self, source, opts['download_dir'], *path)
end
|
65
66
67
|
# File 'lib/jetel/modules/module.rb', line 65
def transform_dir(source, opts)
Module.transform_dir(self, source, opts)
end
|
77
78
79
|
# File 'lib/jetel/modules/module.rb', line 77
def transformed_file(source, opts)
Module.transformed_file(self, source, opts)
end
|
#unzip(source, options = {}) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/jetel/modules/module.rb', line 101
def unzip(source, options = {})
downloaded_file = downloaded_file(source, options)
dest_dir = (source, options)
FileUtils.mkdir_p(dest_dir)
Zip::ZipFile.open(downloaded_file) do |zip_file|
zip_file.each do |entry|
puts "Extracting #{entry.name}"
dest_file = File.join(dest_dir, entry.name.split('/').last)
FileUtils.rm_rf(dest_file)
entry.(dest_file)
end
end
end
|