-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from petergoldstein/feature/make_multi_json_op…
…tional Make MultiJson optional for Ruby 1.9+
- Loading branch information
Showing
3 changed files
with
23 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |