Module: CloudControl::Params
- Included in:
- Client
- Defined in:
- lib/cloudcontrol/params.rb
Instance Method Summary collapse
- #camelize_keys(arg) ⇒ Object
- #symbolize_keys(arg) ⇒ Object
- #underscore_keys(arg) ⇒ Object
- #url_query(params) ⇒ Object
Instance Method Details
#camelize_keys(arg) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cloudcontrol/params.rb', line 45 def camelize_keys(arg) case arg when Array arg.map { |elem| camelize_keys elem } when Hash Hash[ arg.map { |key, value| k = key.is_a?(String) ? key.camelize(:lower) : key k = key.is_a?(Symbol) ? key.to_s.camelize(:lower).to_sym : key v = camelize_keys value [k,v] }] else arg end end |
#symbolize_keys(arg) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cloudcontrol/params.rb', line 13 def symbolize_keys(arg) case arg when Array arg.map { |elem| symbolize_keys elem } when Hash Hash[ arg.map { |key, value| k = key.is_a?(String) ? key.to_sym : key v = symbolize_keys value [k,v] }] else arg end end |
#underscore_keys(arg) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cloudcontrol/params.rb', line 29 def underscore_keys(arg) case arg when Array arg.map { |elem| underscore_keys elem } when Hash Hash[ arg.map { |key, value| k = key.is_a?(String) ? key.underscore : key v = underscore_keys value [k,v] }] else arg end end |
#url_query(params) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/cloudcontrol/params.rb', line 3 def url_query(params) params = camelize_keys(params) qitems = [] params.each do |k, vs| vs = [vs].flatten.compact # remove nil values vs.each {|v| qitems << "#{k}=#{v}"} end qitems.join('&') end |