Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make MultiJson optional for Ruby 1.9+ #33

Merged
merged 1 commit into from
Jan 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "https://rubygems.org"

gem 'json', '>= 1.2.4'
gem 'multi_json', '~> 1.0'
gem 'multi_json', '~> 1.0', :platforms => :ruby_18
gem 'jruby-openssl', :platforms => :jruby

gem 'rubysl', '~> 2.0', :platforms => :rbx
Expand Down
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Echoe.new('jwt', '0.1.11') do |p|
p.author = "Jeff Lindsay"
p.email = "[email protected]"
p.ignore_pattern = ["tmp/*"]
p.runtime_dependencies = ["multi_json >=1.5"]
p.development_dependencies = ["echoe >=4.6.3"]
p.licenses = "MIT"
end
Expand Down
30 changes: 22 additions & 8 deletions lib/jwt/json.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
module JWT
module Json
if RUBY_VERSION >= "1.9" && !defined?(MultiJson)
require 'json'

require "multi_json"
def decode_json(encoded)
JSON.parse(encoded)
rescue JSON::ParserError
raise JWT::DecodeError.new("Invalid segment encoding")
end

def decode_json(encoded)
MultiJson.decode(encoded)
rescue MultiJson::LoadError
raise JWT::DecodeError.new("Invalid segment encoding")
end
def encode_json(raw)
JSON.generate(raw)
end

else
require "multi_json"

def decode_json(encoded)
MultiJson.decode(encoded)
rescue MultiJson::LoadError
raise JWT::DecodeError.new("Invalid segment encoding")
end

def encode_json(raw)
MultiJson.encode(raw)
def encode_json(raw)
MultiJson.encode(raw)
end
end
end
end