Module: Componentr
- Defined in:
- lib/componentr.rb,
lib/componentr/version.rb
Defined Under Namespace
Classes: Inputr, Jobr, Translator
Constant Summary
collapse
- VERSION =
"0.0.3"
Class Method Summary
collapse
Class Method Details
.hi(language) ⇒ Object
8
9
10
11
|
# File 'lib/componentr.rb', line 8
def self.hi(language)
translator = Translator.new(language)
translator.hi
end
|
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
|
# File 'lib/componentr.rb', line 30
def self.inputr
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: coomponentr [options]"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
end
opts.on("-p", "--[no-]passthru", "Passthru Arguments") do |p|
options[:passthru] = p
end
options[:wargs] = nil
opts.on( '-a', '--wargs JSON', 'workflow arguments to be passed along (JSON.to_s arg)' ) do |json|
options[:wargs] = json
end
end.parse!
wargs = options[:wargs] rescue nil
options.delete(:wargs)
wargs = JSON.parse(wargs) if wargs
input = ARGV
inputs = input.map { |i|
begin
candidate = JSON.parse(i)
if candidate && candidate['wargs']
wargs.merge!(candidate)
nil
end
rescue Exception => e
i
end
}.compact
if ! wargs
candidate_args = ARGF.read rescue ''
whatever = ARGF.read rescue ''
candidate_json = JSON.parse(candidate_args) rescue {}
wargs = candidate_json
end
return options, wargs, inputs
end
|
.outputr(wargs, output) ⇒ Object
90
91
92
93
|
# File 'lib/componentr.rb', line 90
def self.outputr(wargs, output)
$stdout.puts wargs.to_json.to_s if wargs
output.map {|o| $stdout.puts o }
end
|
.process(options, wargs, input) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/componentr.rb', line 13
def self.process(options, wargs, input)
begin
raise Exception if wargs && wargs['status'] == 'error'
job = Jobr.new
wargs = job.process(options, wargs, input)
return wargs, input
rescue Exception => e
wargs['history'] = {} if ! wargs['history']
wargs['history']["#{Time.now.to_i}#{rand}"] = "wargs error by #{self.class}"
return wargs, input
end
end
|
.read_eval_print ⇒ Object
95
96
97
98
99
|
# File 'lib/componentr.rb', line 95
def self.read_eval_print
outputr(*process(*inputr))
rescue Exception => e
$stderr.puts e.message
end
|