Module: Fanforce::InternalUtils

Defined in:
lib/fanforce/utils/utils.rb

Class Method Summary collapse

Class Method Details

.modify_keys(object, &modifier) ⇒ Object

:nodoc:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fanforce/utils/utils.rb', line 93

def self.modify_keys(object, &modifier) #:nodoc:
  case object
    when Array
      object.map do |value|
        modify_keys(value, &modifier)
      end
    when Hash
      object.inject({}) do |result, (key, value)|
        new_key   = modifier.call(key)
        new_value = modify_keys(value, &modifier)
        result.merge! new_key => new_value
      end
    else
      object
  end
end

.to_param(obj, namespace = nil) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fanforce/utils/utils.rb', line 110

def self.to_param(obj, namespace=nil)
  if obj.is_a?(Array)
    collect { |e| to_param(e) }.join '/'
  elsif obj.is_a?(Hash)
    to_query_string(obj, namespace)
  elsif obj.is_a?(NilClass)
    obj
  elsif obj.is_a?(TrueClass)
    obj
  elsif obj.is_a?(FalseClass)
    obj
  elsif obj.is_a?(Object)
    obj.to_s
  end
end