Module: Babl
- Defined in:
- lib/babl.rb,
lib/babl/module_response.rb
Defined Under Namespace
Classes: ModuleError, ModuleNameFormatIncorrectError, ModuleResponse, UnknownModuleError
Class Method Summary
collapse
Class Method Details
.bin_path ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/babl.rb', line 26
def self.bin_path
system = `which babl-rpc`.strip
if system.empty?
bin = 'babl-rpc_'
bin += "linux_amd64" if RUBY_PLATFORM =~ /linux/
bin += "darwin_amd64" if RUBY_PLATFORM =~ /darwin/
File.expand_path("../../bin/#{bin}", __FILE__)
else
STDERR.puts "Warn: Using locally installed binary '#{system}'"
system
end
end
|
.call!(name, opts = {}) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/babl.rb', line 55
def self.call! name, opts = {}
begin
ModuleResponse.new(client[:babl].call('Module', options_to_rpc_parameter(name, opts)))
rescue Quartz::ResponseError => e
if e.message == 'babl-rpc: module name format incorrect'
raise ModuleNameFormatIncorrectError.new('Module Name Format Incorrect')
else
raise
end
end
end
|
.client ⇒ Object
43
44
45
|
# File 'lib/babl.rb', line 43
def self.client
@client ||= Quartz::Client.new(bin_path: bin_path)
end
|
.module!(name, opts = {}) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/babl.rb', line 47
def self.module! name, opts = {}
res = call! name, opts
if res.exitcode != 0
raise ModuleError.new(stdout: res.stdout, stderr: res.stderr, exitcode: res.exitcode)
end
res.stdout
end
|
.options_to_rpc_parameter(name, opts) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/babl.rb', line 67
def self.options_to_rpc_parameter name, opts
params = {'Name' => name}
if input = opts[:in]
if input.is_a?(ModuleResponse)
if input.payload_url
params['PayloadUrl'] = input.payload_url
else
params['Stdin'] = Base64.encode64(input.stdout)
end
else
params['Stdin'] = Base64.encode64(input)
end
end
if opts[:payload_url]
params['PayloadUrl'] = opts[:payload_url]
end
if opts[:env]
params['Env'] = opts[:env].inject({}) { |h, (k,v)| h[k.to_s] = v.to_s; h }
end
if opts[:endpoint]
params['BablEndpoint'] = opts[:endpoint]
end
params
end
|
.version ⇒ Object
39
40
41
|
# File 'lib/babl.rb', line 39
def self.version
`#{bin_path} -version`.strip
end
|