Skip to content

Commit

Permalink
Don't monkey-patch Hash anymore, to solve ActiveSupport conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuravaux committed May 20, 2011
1 parent 71f9544 commit 24e78ca
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/gattica.rb
Expand Up @@ -12,7 +12,7 @@

# internal
require 'gattica/version'
require 'gattica/core_extensions'
require 'gattica/hash_extensions'
require 'gattica/convertible'
require 'gattica/exceptions'
require 'gattica/user'
Expand Down
1 change: 1 addition & 0 deletions lib/gattica/auth.rb
Expand Up @@ -18,6 +18,7 @@ class Auth
# Try to authenticate the user
def initialize(http, user)
options = OPTIONS.merge(user.to_h)
options.extend HashExtensions

response, data = http.post(SCRIPT_NAME, options.to_query, HEADERS)
if response.code != '200'
Expand Down
2 changes: 1 addition & 1 deletion lib/gattica/convertible.rb
Expand Up @@ -10,7 +10,7 @@ def to_h
instance_variables.each do |var|
output.merge!({ var[1..-1] => instance_variable_get(var) }) unless var == '@xml' # exclude the whole XML dump
end
output
output.tap { |h| h.include HashExtensions }
end

# output nice inspect syntax
Expand Down
25 changes: 0 additions & 25 deletions lib/gattica/core_extensions.rb

This file was deleted.

20 changes: 20 additions & 0 deletions lib/gattica/hash_extensions.rb
@@ -0,0 +1,20 @@
module Gattica
module HashExtensions

def to_query
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
self.collect do |key, value|
"#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
end.sort * '&'
end

def key
self.keys.first if self.length == 1
end

def value
self.values.first if self.length == 1
end

end
end

0 comments on commit 24e78ca

Please sign in to comment.