multi_json 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
@@ -1,5 +1,5 @@
1
- README.rdoc
2
- lib/**/*.rb
1
+ LICENSE.md
2
+ README.md
3
3
  bin/*
4
4
  features/**/*.feature
5
- LICENSE
5
+ lib/**/*.rb
File without changes
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
- --format=nested
2
+ --format=nested
3
+ --backtrace
data/Gemfile CHANGED
@@ -1,11 +1,7 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rake', '~> 0.8'
6
- gem 'rspec', '~> 2.5'
7
- gem 'rcov', '~> 0.9', :platforms => [:mri, :jruby]
1
+ source 'http://rubygems.org'
8
2
 
9
3
  gem 'json', '~> 1.4', :require => nil
10
4
  gem 'json_pure', '~> 1.4', :require => nil
11
- gem 'yajl-ruby', '~> 0.7', :require => nil, :platforms => :ruby
5
+ gem 'yajl-ruby', '~> 0.7', :require => nil
6
+
7
+ gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Michael Bleigh and Intridea, Inc.
1
+ Copyright (c) 2010 Michael Bleigh, Josh Kalderimis, Erik Michaels-Ober, and Intridea, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -0,0 +1,70 @@
1
+ MultiJSON
2
+ =========
3
+
4
+ Lots of Ruby libraries utilize JSON parsing in some form, and everyone has
5
+ their favorite JSON library. In order to best support multiple JSON parsers and
6
+ libraries, <tt>multi_json</tt> is a general-purpose swappable JSON backend
7
+ library. You use it like so:
8
+
9
+ require 'multi_json'
10
+
11
+ MultiJson.engine = :yajl
12
+ MultiJson.decode('{"abc":"def"}') # decoded using Yajl
13
+
14
+ MultiJson.engine = :json_gem
15
+ MultiJson.engine = MultiJson::Engines::JsonGem # equivalent to previous line
16
+ MultiJson.encode({:abc => 'def'}) # encoded using the JSON gem
17
+
18
+ The <tt>engine</tt> setter takes either a symbol or a class (to allow for
19
+ custom JSON parsers) that responds to both <tt>.decode</tt> and
20
+ <tt>.encode</tt> at the class level.
21
+
22
+ MultiJSON tries to have intelligent defaulting. That is, if you have any of the
23
+ supported engines already loaded, it will utilize them before attempting to
24
+ load any. When loading, libraries are ordered by speed. First Yajl-Ruby, then
25
+ the JSON gem, then JSON pure. If no JSON library is available, MultiJSON falls
26
+ back to a bundled version of [OkJson](https://github.com/kr/okjson).
27
+
28
+ Continuous Integration
29
+ ----------------------
30
+ [![Build Status](http://travis-ci.org/intridea/multi_json.png)](http://travis-ci.org/intridea/multi_json)
31
+
32
+ Contributing
33
+ ------------
34
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
35
+
36
+ Here are some ways *you* can contribute:
37
+
38
+ * by using alpha, beta, and prerelease versions
39
+ * by reporting bugs
40
+ * by suggesting new features
41
+ * by writing or editing documentation
42
+ * by writing specifications
43
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
44
+ * by refactoring code
45
+ * by closing [issues](https://github.com/intridea/multi_json/issues)
46
+ * by reviewing patches
47
+
48
+ Submitting an Issue
49
+ -------------------
50
+ We use the [GitHub issue tracker](https://github.com/intridea/multi_json/issues) to track bugs and
51
+ features. Before submitting a bug report or feature request, check to make sure it hasn't already
52
+ been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
53
+ bug report, please include a [Gist](https://gist.github.com/) that includes a stack trace and any
54
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
55
+ operating system. Ideally, a bug report should include a pull request with failing specs.
56
+
57
+ Submitting a Pull Request
58
+ -------------------------
59
+ 1. Fork the project.
60
+ 2. Create a topic branch.
61
+ 3. Implement your feature or bug fix.
62
+ 4. Add specs for your feature or bug fix.
63
+ 5. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 4.
64
+ 6. Commit and push your changes.
65
+ 7. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
66
+
67
+ Copyright
68
+ ---------
69
+ Copyright (c) 2010 Michael Bleigh, Josh Kalderimis, Erik Michaels-Ober, and Intridea, Inc.
70
+ See [LICENSE](https://github.com/intridea/multi_json/blob/master/LICENSE.md) for details.
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
- require 'rubygems'
1
+ #!/usr/bin/env rake
2
2
  begin
3
3
  require 'bundler'
4
4
  Bundler::GemHelper.install_tasks
5
5
  rescue LoadError => e
6
- puts "although not required, it's recommended that you use bundler during development"
6
+ warn "[WARNING]: It is recommended that you use bundler during development: gem install bundler"
7
7
  end
8
8
 
9
9
  require 'rspec/core/rake_task'
@@ -11,27 +11,13 @@ desc "Run all examples"
11
11
  RSpec::Core::RakeTask.new(:spec)
12
12
 
13
13
  task :default => :spec
14
+ task :test => :spec
14
15
 
15
- require 'rake/rdoctask'
16
+ require 'rdoc/task'
16
17
  Rake::RDocTask.new do |rdoc|
17
18
  rdoc.rdoc_dir = 'rdoc'
18
19
  rdoc.title = "multi_json #{MultiJson::VERSION}"
19
- rdoc.rdoc_files.include('README*')
20
+ rdoc.rdoc_files.include('README.md')
21
+ rdoc.rdoc_files.include('LICENSE.md')
20
22
  rdoc.rdoc_files.include('lib/**/*.rb')
21
23
  end
22
-
23
- task :cleanup_rcov_files do
24
- rm_rf 'coverage.data'
25
- end
26
-
27
- begin
28
- namespace :spec do
29
- desc "Run all examples using rcov"
30
- RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
31
- t.rcov = true
32
- t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
33
- t.rcov_opts << %[--text-report --sort coverage --no-html --aggregate coverage.data]
34
- end
35
- end
36
- rescue LoadError
37
- end
@@ -16,20 +16,31 @@ module MultiJson
16
16
  end
17
17
 
18
18
  def self.symbolize_keys(object) #:nodoc:
19
- return object unless object.is_a?(Hash)
20
- object.inject({}) do |result, (key, value)|
21
- new_key = key.is_a?(String) ? key.to_sym : key
22
- new_value = value.is_a?(Hash) ? symbolize_keys(value) : value
23
- result.merge! new_key => new_value
19
+ modify_keys(object) do |key|
20
+ key.is_a?(String) ? key.to_sym : key
24
21
  end
25
22
  end
26
23
 
27
24
  def self.stringify_keys(object) #:nodoc:
28
- return object unless object.is_a?(Hash)
29
- object.inject({}) do |result, (key, value)|
30
- new_key = key.is_a?(Symbol) ? key.to_s : key
31
- new_value = value.is_a?(Hash) ? stringify_keys(value) : value
32
- result.merge! new_key => new_value
25
+ modify_keys(object) do |key|
26
+ key.is_a?(Symbol) ? key.to_s : key
27
+ end
28
+ end
29
+
30
+ def self.modify_keys(object, &modifier) #:nodoc:
31
+ case object
32
+ when Array
33
+ object.map do |value|
34
+ modify_keys(value, &modifier)
35
+ end
36
+ when Hash
37
+ object.inject({}) do |result, (key, value)|
38
+ new_key = modifier.call(key)
39
+ new_value = modify_keys(value, &modifier)
40
+ result.merge! new_key => new_value
41
+ end
42
+ else
43
+ object
33
44
  end
34
45
  end
35
46
  end
@@ -1,3 +1,3 @@
1
1
  module MultiJson
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -1,25 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require File.expand_path("../lib/multi_json/version", __FILE__)
3
3
 
4
- Gem::Specification.new do |s|
5
- s.name = "multi_json"
6
- s.version = MultiJson::VERSION
7
-
8
- s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
9
-
10
- s.authors = ["Michael Bleigh"]
11
- s.email = ["michael@intridea.com"]
12
- s.summary = %q{A gem to provide swappable JSON backends.}
13
- s.description = %q{A gem to provide swappable JSON backends utilizing Yajl::Ruby, the JSON gem, JSON pure, or a vendored version of okjson.}
14
- s.homepage = "http://github.com/intridea/multi_json"
15
-
16
- s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
17
- s.rdoc_options = ["--charset=UTF-8"]
18
-
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
20
- s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
-
23
- s.require_paths = ["lib"]
4
+ Gem::Specification.new do |gem|
5
+ gem.add_development_dependency 'rake', '~> 0.9'
6
+ gem.add_development_dependency 'rdoc', '3.5.1'
7
+ gem.add_development_dependency 'rspec', '~> 2.6'
8
+ gem.add_development_dependency 'simplecov', '~> 0.4'
9
+ gem.authors = ["Michael Bleigh", "Josh Kalderimis", "Erik Michaels-Ober"]
10
+ gem.description = %q{A gem to provide swappable JSON backends utilizing Yajl::Ruby, the JSON gem, JSON pure, or a vendored version of okjson.}
11
+ gem.email = ['michael@intridea.com', 'josh.kalderimis@gmail.com', 'sferik@gmail.com']
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
13
+ gem.extra_rdoc_files = ['LICENSE.md', 'README.md']
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.homepage = 'http://github.com/intridea/multi_json'
16
+ gem.name = 'multi_json'
17
+ gem.rdoc_options = ["--charset=UTF-8"]
18
+ gem.require_paths = ['lib']
19
+ gem.required_rubygems_version = Gem::Requirement.new(">= 1.3.6")
20
+ gem.summary = %q{A gem to provide swappable JSON backends.}
21
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ gem.version = MultiJson::VERSION
24
23
  end
25
-
@@ -0,0 +1,11 @@
1
+ begin
2
+ require 'bundler'
3
+ Bundler.setup
4
+ rescue LoadError
5
+ warn "[WARNING]: It is recommended that you use bundler during development: gem install bundler"
6
+ end
7
+
8
+ require 'simplecov'
9
+ SimpleCov.start
10
+ require 'rspec'
11
+ require 'multi_json'
@@ -1,9 +1,9 @@
1
- require 'spec_helper'
1
+ require 'helper'
2
2
  require 'stringio'
3
-
3
+
4
4
  class MockDecoder
5
5
  def self.decode(string, options = {})
6
- { 'abc' => 'def' }
6
+ {'abc' => 'def'}
7
7
  end
8
8
 
9
9
  def self.encode(string)
@@ -26,16 +26,10 @@ describe "MultiJson" do
26
26
  end
27
27
  end
28
28
  end
29
-
29
+
30
30
  it 'defaults to the best available gem' do
31
- # the yajl-ruby gem does not work on jruby, so the best engine is the JsonGem engine
32
- if jruby?
33
- require 'json'
34
- MultiJson.engine.name.should == 'MultiJson::Engines::JsonGem'
35
- else
36
- require 'yajl'
37
- MultiJson.engine.name.should == 'MultiJson::Engines::Yajl'
38
- end
31
+ require 'yajl'
32
+ MultiJson.engine.name.should == 'MultiJson::Engines::Yajl'
39
33
  end
40
34
 
41
35
  it 'is settable via a symbol' do
@@ -70,8 +64,23 @@ describe "MultiJson" do
70
64
  end
71
65
 
72
66
  it 'encodes symbol keys as strings' do
73
- encoded_json = MultiJson.encode({ :foo => { :bar => 'baz' } })
74
- MultiJson.decode(encoded_json).should == { 'foo' => { 'bar' => 'baz' } }
67
+ [
68
+ [
69
+ { :foo => { :bar => 'baz' } },
70
+ { 'foo' => { 'bar' => 'baz' } }
71
+ ],
72
+ [
73
+ [ { :foo => { :bar => 'baz' } } ],
74
+ [ { 'foo' => { 'bar' => 'baz' } } ],
75
+ ],
76
+ [
77
+ { :foo => [ { :bar => 'baz' } ] },
78
+ { 'foo' => [ { 'bar' => 'baz' } ] },
79
+ ]
80
+ ].each do |example, expected|
81
+ encoded_json = MultiJson.encode(example)
82
+ MultiJson.decode(encoded_json).should == expected
83
+ end
75
84
  end
76
85
 
77
86
  it 'encodes rootless JSON' do
@@ -95,14 +104,29 @@ describe "MultiJson" do
95
104
  encoded_json = MultiJson.encode(:a => 1, :b => {:c => 2})
96
105
  MultiJson.decode(encoded_json).should == { "a" => 1, "b" => { "c" => 2 } }
97
106
  end
98
-
107
+
99
108
  it "properly decodes valid JSON in StringIOs" do
100
109
  json = StringIO.new('{"abc":"def"}')
101
110
  MultiJson.decode(json).should == { 'abc' => 'def' }
102
111
  end
103
112
 
104
113
  it 'allows for symbolization of keys' do
105
- MultiJson.decode('{"abc":{"def":"hgi"}}', :symbolize_keys => true).should == { :abc => { :def => 'hgi' } }
114
+ [
115
+ [
116
+ '{"abc":{"def":"hgi"}}',
117
+ { :abc => { :def => 'hgi' } }
118
+ ],
119
+ [
120
+ '[{"abc":{"def":"hgi"}}]',
121
+ [ { :abc => { :def => 'hgi' } } ]
122
+ ],
123
+ [
124
+ '{"abc":[{"def":"hgi"}]}',
125
+ { :abc => [ { :def => 'hgi' } ] }
126
+ ],
127
+ ].each do |example, expected|
128
+ MultiJson.decode(example, :symbolize_keys => true).should == expected
129
+ end
106
130
  end
107
131
  end
108
132
  end
metadata CHANGED
@@ -2,36 +2,83 @@
2
2
  name: multi_json
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.2
5
+ version: 1.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Bleigh
9
+ - Josh Kalderimis
10
+ - Erik Michaels-Ober
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
14
 
13
- date: 2011-05-12 00:00:00 +02:00
14
- default_executable:
15
- dependencies: []
16
-
15
+ date: 2011-05-23 00:00:00 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rake
19
+ prerelease: false
20
+ requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: "0.9"
26
+ type: :development
27
+ version_requirements: *id001
28
+ - !ruby/object:Gem::Dependency
29
+ name: rdoc
30
+ prerelease: false
31
+ requirement: &id002 !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - "="
35
+ - !ruby/object:Gem::Version
36
+ version: 3.5.1
37
+ type: :development
38
+ version_requirements: *id002
39
+ - !ruby/object:Gem::Dependency
40
+ name: rspec
41
+ prerelease: false
42
+ requirement: &id003 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: "2.6"
48
+ type: :development
49
+ version_requirements: *id003
50
+ - !ruby/object:Gem::Dependency
51
+ name: simplecov
52
+ prerelease: false
53
+ requirement: &id004 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: "0.4"
59
+ type: :development
60
+ version_requirements: *id004
17
61
  description: A gem to provide swappable JSON backends utilizing Yajl::Ruby, the JSON gem, JSON pure, or a vendored version of okjson.
18
62
  email:
19
63
  - michael@intridea.com
64
+ - josh.kalderimis@gmail.com
65
+ - sferik@gmail.com
20
66
  executables: []
21
67
 
22
68
  extensions: []
23
69
 
24
70
  extra_rdoc_files:
25
- - LICENSE
26
- - README.rdoc
71
+ - LICENSE.md
72
+ - README.md
27
73
  files:
28
74
  - .document
75
+ - .gemtest
29
76
  - .gitignore
30
77
  - .rspec
31
78
  - .travis.yml
32
79
  - Gemfile
33
- - LICENSE
34
- - README.rdoc
80
+ - LICENSE.md
81
+ - README.md
35
82
  - Rakefile
36
83
  - lib/multi_json.rb
37
84
  - lib/multi_json/engines/json_gem.rb
@@ -41,10 +88,8 @@ files:
41
88
  - lib/multi_json/vendor/ok_json.rb
42
89
  - lib/multi_json/version.rb
43
90
  - multi_json.gemspec
91
+ - spec/helper.rb
44
92
  - spec/multi_json_spec.rb
45
- - spec/spec.opts
46
- - spec/spec_helper.rb
47
- has_rdoc: true
48
93
  homepage: http://github.com/intridea/multi_json
49
94
  licenses: []
50
95
 
@@ -68,11 +113,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
113
  requirements: []
69
114
 
70
115
  rubyforge_project:
71
- rubygems_version: 1.6.2
116
+ rubygems_version: 1.8.3
72
117
  signing_key:
73
118
  specification_version: 3
74
119
  summary: A gem to provide swappable JSON backends.
75
120
  test_files:
121
+ - spec/helper.rb
76
122
  - spec/multi_json_spec.rb
77
- - spec/spec.opts
78
- - spec/spec_helper.rb
@@ -1,30 +0,0 @@
1
- = MultiJSON
2
-
3
- Lots of Ruby libraries utilize JSON parsing in some form, and everyone has their favorite JSON library. In order to best support multiple JSON parsers and libraries, <tt>multi_json</tt> is a general-purpose swappable JSON backend library. You use it like so:
4
-
5
- require 'multi_json'
6
-
7
- MultiJson.engine = :yajl
8
- MultiJson.decode('{"abc":"def"}') # decoded using Yajl
9
-
10
- MultiJson.engine = :json_gem
11
- MultiJson.engine = MultiJson::Engines::JsonGem # equivalent to previous line
12
- MultiJson.encode({:abc => 'def'}) # encoded using the JSON gem
13
-
14
- The <tt>engine</tt> setter takes either a symbol or a class (to allow for custom JSON parsers) that responds to both <tt>.decode</tt> and <tt>.encode</tt> at the class level.
15
-
16
- MultiJSON tries to have intelligent defaulting. That is, if you have any of the supported engines already loaded, it will utilize them before attempting to load any. When loading, libraries are ordered by speed. First Yajl-Ruby, then the JSON gem, then JSON pure. If no JSON library is available, MultiJSON falls back to a bundled version of <a href="https://github.com/kr/okjson">OkJson</a>.
17
-
18
- == Note on Patches/Pull Requests
19
-
20
- * Fork the project.
21
- * Make your feature addition or bug fix.
22
- * Add tests for it. This is important so I don't break it in a
23
- future version unintentionally.
24
- * Commit, do not mess with rakefile, version, or history.
25
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
26
- * Send me a pull request. Bonus points for topic branches.
27
-
28
- == Copyright
29
-
30
- Copyright (c) 2010 Michael Bleigh and Intridea, Inc. See LICENSE for details.
@@ -1,2 +0,0 @@
1
- --color
2
- --format=nested
@@ -1,15 +0,0 @@
1
- begin
2
- require 'bundler'
3
- rescue LoadError
4
- puts "although not required, it's recommended that you use bundler during development"
5
- end
6
-
7
- require 'rspec'
8
- require 'rspec/autorun'
9
-
10
- $VERBOSE = true
11
- require 'multi_json'
12
-
13
- def jruby?
14
- defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
15
- end