Class: DEIS::Parse
- Inherits:
-
Object
- Object
- DEIS::Parse
- Defined in:
- lib/rdeis/parse.rb
Class Method Summary collapse
- .first_proc ⇒ Object
- .JSON_to_set(json) ⇒ Object
- .JSON_to_unset(json) ⇒ Object
-
.key(pair) ⇒ Object
finds just the key from a string like KEY=VALUE.
-
.list_array_to_var_string_array(data) ⇒ Object
takes the array of [ [k, v], [k, v] ] and converts back to string K=V.
- .procs ⇒ Object
-
.value(pair) ⇒ Object
finds just the value from a string like KEY=VALUE.
-
.var_array(vars) ⇒ Object
vars is an array from the cli taking the form of: KEY=VALUE KEY1=V1 KEY2=V2 KEY1 KEY2.
Class Method Details
.first_proc ⇒ Object
69 70 71 72 73 74 |
# File 'lib/rdeis/parse.rb', line 69 def self.first_proc if (procs=DEIS::Parse.procs) && ! procs.nil? && procs.length > 0 return "#{procs.first}=1" end nil end |
.JSON_to_set(json) ⇒ Object
45 46 47 48 49 |
# File 'lib/rdeis/parse.rb', line 45 def self.JSON_to_set(json) cmd = "" json.each{|k,v| cmd += if v.to_s.length > 0 && v.to_s != "null" then "#{k}=\"#{v}\" " else "#{k} " end} cmd + " 2>&1" end |
.JSON_to_unset(json) ⇒ Object
51 52 53 54 55 |
# File 'lib/rdeis/parse.rb', line 51 def self.JSON_to_unset(json) cmd = "" json.each{|k,v| cmd += "#{k} "} cmd + " 2>&1" end |
.key(pair) ⇒ Object
finds just the key from a string like KEY=VALUE
18 19 20 21 22 23 24 |
# File 'lib/rdeis/parse.rb', line 18 def self.key(pair) # start by assuming there might be no value or = symbol index = pair.length - 1 index = pair.index("=") - 1 if ! pair.index("=").nil? # return the sub string pair[0..index] end |
.list_array_to_var_string_array(data) ⇒ Object
takes the array of [ [k, v], [k, v] ] and converts back to string K=V
39 40 41 42 43 |
# File 'lib/rdeis/parse.rb', line 39 def self.list_array_to_var_string_array(data) out = [] data.each{|sub| out.push("#{sub.first}"+ if !sub[1].nil? then "=#{sub[1]}" else "" end) } out end |
.procs ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rdeis/parse.rb', line 57 def self.procs procs = [] file = Dir.pwd+"/Procfile" if File.exists?(file) File.open(file, "r") {|f| f.read}.split("\n").each do |r| key = r.split(":").first procs.push(key) end end procs end |
.value(pair) ⇒ Object
finds just the value from a string like KEY=VALUE
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rdeis/parse.rb', line 27 def self.value(pair) #if theres no = then presume no value, just key, so default to nil index = pair.index("=") length = pair.length - 1 if ! index.nil? pair[index+1..length] else nil end end |
.var_array(vars) ⇒ Object
vars is an array from the cli taking the form of: KEY=VALUE KEY1=V1 KEY2=V2 KEY1 KEY2
8 9 10 11 12 13 14 15 |
# File 'lib/rdeis/parse.rb', line 8 def self.var_array(vars) parsed = [] if ! vars.nil? && vars.length > 0 vars.each{ |pair| parsed.push ( {:k =>DEIS::Parse.key(pair), :v=>DEIS::Parse.value(pair) } ) } end # reverse so the last value of the key is used, then sort alpabetically, ignoring case parsed.reverse.uniq {|r| r[:k]}.sort{|a ,b | a[:k].downcase <=> b[:k].downcase} end |