Sha256: d47a0884ad1324e8d7ca5d519e10e2c09784e39b109445c2d67ee7f9a245633b

Contents?: true

Size: 852 Bytes

Versions: 9

Compression:

Stored size: 852 Bytes

Contents

class BasicObject #:nodoc:
  instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval/ }
end unless defined?(BasicObject)

# monkey patching:
class Hash
  # Taken from ActiveSupport
  def symbolize_keys
    inject({}) do |options, (key, value)|
      options[(key.to_sym rescue key) || key] = value
      options
    end
  end

  # Taken from ActiveSupport  
  def stringify_keys
    inject({}) do |options, (key, value)|
      options[key.to_s] = value
      options
    end
  end


  # This is by no means the standard way to transform ruby objects into query parameters
  # but it is targeted at our own needs
  def to_params
    params = ''

    each do |k, v|
      if v.is_a?(Array)
        params << "#{k}=#{v.join(",")}&"
      else
        params << "#{k}=#{v.to_s}&"
      end
    end

    params.chop! 
    params
  end

end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
crohr-restfully-0.1.1 lib/restfully/extensions.rb
crohr-restfully-0.2.1 lib/restfully/extensions.rb
crohr-restfully-0.2.2 lib/restfully/extensions.rb
restfully-0.3.2 lib/restfully/extensions.rb
restfully-0.3.1 lib/restfully/extensions.rb
restfully-0.3.0 lib/restfully/extensions.rb
restfully-0.2.3 lib/restfully/extensions.rb
restfully-0.2.2 lib/restfully/extensions.rb
restfully-0.2.1 lib/restfully/extensions.rb