Module: IronWorkerNG::Code::Runtime::Ruby
Instance Method Summary
collapse
#merge_gemfile
#merge_gem, #merge_gem_dependency_fixate
#merge_exec
Instance Method Details
#install(standalone = false) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/iron_worker_ng/code/runtime/ruby.rb', line 121
def install(standalone = false)
gemfile_dir = nil
gemfile = nil
if standalone
gemfile = File.open('Gemfile', 'w')
else
gemfile_dir = ::Dir.tmpdir + '/' + ::Dir::Tmpname.make_tmpname('iron-worker-ng-', 'gemfile')
FileUtils.mkdir(gemfile_dir)
gemfile = File.open(gemfile_dir + '/Gemfile', 'w')
end
gemfile.puts('source \'http://rubygems.org\'')
deps = @features.reject { |f| f.class != IronWorkerNG::Feature::Ruby::MergeGemDependency::Feature }
deps.each do |dep|
gemfile.puts("gem '#{dep.name}', '#{dep.version}'")
end
gemfile.close
if standalone
puts `bundle install --standalone`
else
puts `cd #{gemfile_dir} && bundle install`
FileUtils.rm_r(gemfile_dir)
end
end
|
#runtime_bundle(container, local = false) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/iron_worker_ng/code/runtime/ruby.rb', line 16
def runtime_bundle(container, local = false)
container.get_output_stream(@dest_dir + '__runner__.rb') do |runner|
runner.write "# \#{IronWorkerNG.full_version}\n\nmodule IronWorkerNG\n\#{File.read(File.dirname(__FILE__) + '/../../../3rdparty/hashie/merge_initializer.rb')}\n\#{File.read(File.dirname(__FILE__) + '/../../../3rdparty/hashie/indifferent_access.rb')}\nend\n\nclass IronWorkerNGHash < Hash\n include IronWorkerNG::Hashie::Extensions::MergeInitializer\n include IronWorkerNG::Hashie::Extensions::IndifferentAccess\nend\n\nroot = nil\npayload_file = nil\nconfig_file = nil\ntask_id = nil\n\n0.upto($*.length - 2) do |i|\n root = $*[i + 1] if $*[i] == '-d'\n payload_file = $*[i + 1] if $*[i] == '-payload'\n config_file = $*[i + 1] if $*[i] == '-config'\n task_id = $*[i + 1] if $*[i] == '-id'\nend\n\nENV['GEM_PATH'] = ([root + '__gems__'] + (ENV['GEM_PATH'] || '').split(':')).join(':')\nENV['GEM_HOME'] = root + '__gems__'\n\n$:.unshift(\"\\\#{root}\")\n\nrequire 'json'\nrequire 'yaml'\n\n@iron_task_id = task_id\n\n@payload = File.read(payload_file)\n\nparams = {}\nbegin\n params = JSON.parse(@payload)\nrescue\nend\n\n@config = nil\nif config_file\n @config = File.read(config_file)\n begin\n @config = JSON.parse(@config)\n @config = IronWorkerNGHash.new(@config)\n rescue\n # try yaml\n begin\n @config = YAML.load(@config)\n @config = IronWorkerNGHash.new(@config)\n rescue\n end\n end\nend\n\n@params = IronWorkerNGHash.new(params)\n\ndef payload\n @payload\nend\n\ndef config\n @config\nend\n\ndef params\n @params\nend\n\ndef iron_task_id\n @iron_task_id\nend\n\nrequire '\#{File.basename(@exec.path)}'\n\nunless \#{@exec.arg(:class, 0) == nil}\n exec_class = Kernel.const_get('\#{@exec.arg(:class, 0)}')\n exec_inst = exec_class.new\n\n params.keys.each do |param|\n if param.class == String\n if exec_inst.respond_to?(param + '=')\nexec_inst.send(param + '=', params[param])\n end\n end\n end\n\n exec_inst.run\nend\n"
end
end
|
#runtime_run_code(local = false) ⇒ Object
115
116
117
118
119
|
# File 'lib/iron_worker_ng/code/runtime/ruby.rb', line 115
def runtime_run_code(local = false)
"ruby __runner__.rb \"$@\"\n"
end
|