module Componentr
Constants
- VERSION
Public Class Methods
hi(language)
click to toggle source
# File lib/componentr.rb, line 8 def self.hi(language) translator = Translator.new(language) translator.hi end
inputr()
click to toggle source
# 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! # if any commnand line args are actually prpoper named wargs, emobody themm wargs = options[:wargs] rescue nil options.delete(:wargs) wargs = JSON.parse(wargs) if wargs # probe input to see if any wargs are in there input = ARGV inputs = input.map { |i| begin candidate = JSON.parse(i) if candidate && candidate['wargs'] # merge into wargs wargs.merge!(candidate) # if merged, we don't need this in stdin nil end rescue Exception => e i end }.compact # get rid of nils # we check to see if its a wargs array, thats it if ! wargs # if we didn't get args on the command line, try file i/o, # this is encountered when a proc gets a pipeline input from stdout # ARGF.each do |line| # $stderr.puts line # end 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)
click to toggle source
# 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)
click to toggle source
# File lib/componentr.rb, line 13 def self.process(options, wargs, input) begin # do something smart with passthru # return wargs, input if wargs && wargs['status'] == 'error' 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()
click to toggle source
# File lib/componentr.rb, line 95 def self.read_eval_print outputr(*process(*inputr)) rescue Exception => e $stderr.puts e.message end