Sha256: 791052e67cdd44db31c885d0d051f1dbe29ca36d7be85d40009a8793d716cdbe

Contents?: true

Size: 837 Bytes

Versions: 9

Compression:

Stored size: 837 Bytes

Contents

module Fanforce::Base::InternalUtils

  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

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

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fanforce-base-2.0.0.rc4 lib/fanforce/base/internal_utils.rb
fanforce-base-2.0.0.rc3 lib/fanforce/base/internal_utils.rb
fanforce-base-2.0.0.rc2 lib/fanforce/base/internal_utils.rb
fanforce-base-2.0.0.rc1 lib/fanforce/base/internal_utils.rb
fanforce-base-1.6.0 lib/fanforce/base/internal_utils.rb
fanforce-base-1.6.0.rc3 lib/fanforce/base/internal_utils.rb
fanforce-base-1.6.0.rc2 lib/fanforce/base/internal_utils.rb
fanforce-base-1.6.0.rc1 lib/fanforce/base/internal_utils.rb
fanforce-base-1.3.0 lib/fanforce/base/internal_utils.rb