Skip to content

Commit

Permalink
bring support for ruby 1.8
Browse files Browse the repository at this point in the history
closes #3
  • Loading branch information
NARKOZ committed Jan 15, 2013
1 parent e4d7dd7 commit e562a7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
language: ruby
rvm: 1.9.3
rvm:
- 1.8.7
- 1.9.3
matrix:
allow_failures:
- rvm: 1.8.7
7 changes: 7 additions & 0 deletions lib/gitlab/objectified_hash.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Gitlab
# Converts hashes to the objects.
class ObjectifiedHash
attr_reader :data

# Creates a new ObjectifiedHash.
def initialize(hash)
@data = hash.inject({}) do |data, (key,value)|
Expand All @@ -10,6 +12,11 @@ def initialize(hash)
end
end

# Patches Object#id in Ruby 1.8
def id
self.data['id']
end

# Delegate to ObjectifiedHash
def method_missing(key)
@data.key?(key.to_s) ? @data[key.to_s] : nil
Expand Down
2 changes: 1 addition & 1 deletion lib/gitlab/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Request
include HTTParty
format :json
headers 'Accept' => 'application/json'
parser Proc.new {|body| parse(body)}
parser Proc.new {|body, _| parse(body)}

# Converts the response body to an ObjectifiedHash.
def self.parse(body)
Expand Down

0 comments on commit e562a7d

Please sign in to comment.