Module: FireAndForget::Utilities

Included in:
FireAndForget
Defined in:
lib/fire_and_forget/utilities.rb

Instance Method Summary collapse

Instance Method Details

#to_arguments(params = {}) ⇒ Object



4
5
6
7
8
# File 'lib/fire_and_forget/utilities.rb', line 4

def to_arguments(params={})
  params.keys.sort { |a, b| a.to_s <=> b.to_s }.map do |key|
    %(--#{key}=#{to_parameter(params[key])})
  end.join(" ")
end

#to_parameter(obj) ⇒ Object

Maps objects to command line parameters suitable for parsing by Thor



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fire_and_forget/utilities.rb', line 12

def to_parameter(obj)
  case obj
  when String
    obj.inspect
  when Array
    obj.map { |o| to_parameter(o) }.join(' ')
  when Hash
    obj.map do |k, v|
      "#{k}:#{to_parameter(obj[k])}"
    end.join(' ')
  when Numeric
    obj
  else
    to_parameter(obj.to_s)
  end
end