multi_json 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,8 +15,16 @@ tmtags
15
15
 
16
16
  ## PROJECT::GENERAL
17
17
  coverage
18
+ doc
18
19
  rdoc
19
- pkg
20
+ log
21
+
22
+ ## BUNDLER
23
+ *.gem
20
24
  .bundle
25
+ pkg
26
+
27
+ ## RCOV
28
+ coverage.data
21
29
 
22
30
  ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=nested
data/Gemfile CHANGED
@@ -1,8 +1,10 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'rspec'
3
+ group :development, :test do
4
+ gem 'activesupport', '~> 3.0', :require => nil
5
+ gem 'json', '~> 1.4', :require => nil
6
+ gem 'json_pure', '~> 1.4', :require => nil
7
+ gem 'yajl-ruby', '~> 0.7', :require => nil
8
+ end
4
9
 
5
- gem 'json', :require => nil
6
- gem 'json_pure', :require => nil
7
- gem 'yajl-ruby', :require => nil
8
- gem 'activesupport', :require => nil
10
+ gemspec
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ multi_json (0.0.5)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ activesupport (3.0.1)
10
+ diff-lcs (1.1.2)
11
+ json (1.4.6)
12
+ json_pure (1.4.6)
13
+ rake (0.8.7)
14
+ rcov (0.9.9)
15
+ rspec (2.0.0)
16
+ rspec-core (= 2.0.0)
17
+ rspec-expectations (= 2.0.0)
18
+ rspec-mocks (= 2.0.0)
19
+ rspec-core (2.0.0)
20
+ rspec-expectations (2.0.0)
21
+ diff-lcs (>= 1.1.2)
22
+ rspec-mocks (2.0.0)
23
+ rspec-core (= 2.0.0)
24
+ rspec-expectations (= 2.0.0)
25
+ yajl-ruby (0.7.8)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ activesupport (~> 3.0)
32
+ json (~> 1.4)
33
+ json_pure (~> 1.4)
34
+ multi_json!
35
+ rake (~> 0.8)
36
+ rcov (~> 0.9)
37
+ rspec (~> 2.0)
38
+ yajl-ruby (~> 0.7)
data/Rakefile CHANGED
@@ -1,49 +1,32 @@
1
1
  require 'rubygems'
2
- require 'rake'
2
+ require 'bundler'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "multi_json"
8
- gem.summary = %Q{A gem to provide swappable JSON backends.}
9
- gem.description = %Q{A gem to provide swappable JSON backends utilizing Yajl::Ruby, the JSON gem, ActiveSupport, or JSON pure.}
10
- gem.email = "michael@intridea.com"
11
- gem.homepage = "http://github.com/intridea/multi_json"
12
- gem.authors = ["Michael Bleigh"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
4
+ Bundler::GemHelper.install_tasks
17
5
 
18
- task :spec => :check_dependencies
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
6
+ require 'rspec/core/rake_task'
7
+ desc "Run all examples"
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
21
9
  end
22
10
 
23
- begin
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- end
11
+ task :cleanup_rcov_files do
12
+ rm_rf 'coverage.data'
13
+ end
29
14
 
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
15
+ namespace :spec do
16
+ desc "Run all examples using rcov"
17
+ RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
18
+ t.rcov = true
19
+ t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
20
+ t.rcov_opts << %[--text-report --sort coverage --no-html --aggregate coverage.data]
34
21
  end
35
-
36
- task :default => :spec
37
- rescue LoadError
38
- puts "RSpec (or a dependency) not available. Install it with: gem install rspec"
39
22
  end
40
23
 
24
+ task :default => :spec
25
+
41
26
  require 'rake/rdoctask'
42
27
  Rake::RDocTask.new do |rdoc|
43
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
-
45
28
  rdoc.rdoc_dir = 'rdoc'
46
- rdoc.title = "multi_json #{version}"
29
+ rdoc.title = "multi_json #{MultiJson::VERSION}"
47
30
  rdoc.rdoc_files.include('README*')
48
31
  rdoc.rdoc_files.include('lib/**/*.rb')
49
32
  end
@@ -1,6 +1,7 @@
1
1
  module MultiJson
2
+ class DecodeError < StandardError; end
2
3
  module_function
3
-
4
+
4
5
  # Get the current engine class.
5
6
  def engine
6
7
  return @engine if @engine
@@ -14,7 +15,7 @@ module MultiJson
14
15
  ["active_support", :active_support],
15
16
  ["json/pure", :json_pure]
16
17
  ]
17
-
18
+
18
19
  # The default engine based on what you currently
19
20
  # have loaded and installed. First checks to see
20
21
  # if any engines are already loaded, then checks
@@ -33,7 +34,7 @@ module MultiJson
33
34
  end
34
35
  end
35
36
  end
36
-
37
+
37
38
  # Set the JSON parser utilizing a symbol, string, or class.
38
39
  # Supported by default are:
39
40
  #
@@ -52,18 +53,22 @@ module MultiJson
52
53
  raise "Did not recognize your engine specification. Please specify either a symbol or a class."
53
54
  end
54
55
  end
55
-
56
+
56
57
  # Decode a JSON string into Ruby.
57
58
  #
58
59
  # <b>Options</b>
59
60
  #
60
61
  # <tt>:symbolize_keys</tt> :: If true, will use symbols instead of strings for the keys.
61
62
  def decode(string, options = {})
62
- engine.decode(string, options)
63
+ begin
64
+ engine.decode(string, options)
65
+ rescue StandardError => exception
66
+ raise DecodeError, exception.inspect
67
+ end
63
68
  end
64
-
69
+
65
70
  # Encodes a Ruby object as JSON.
66
71
  def encode(object)
67
72
  engine.encode(object)
68
73
  end
69
- end
74
+ end
@@ -3,16 +3,16 @@ require 'active_support' unless defined?(::ActiveSupport::JSON)
3
3
  module MultiJson
4
4
  module Engines
5
5
  # Use ActiveSupport to encode/decode JSON.
6
- class ActiveSupport
6
+ class ActiveSupport
7
7
  def self.decode(string, options = {}) #:nodoc:
8
8
  hash = ::ActiveSupport::JSON.decode(string)
9
9
  options[:symbolize_keys] ? symbolize_keys(hash) : hash
10
10
  end
11
-
11
+
12
12
  def self.encode(object) #:nodoc:
13
13
  ::ActiveSupport::JSON.encode(object)
14
14
  end
15
-
15
+
16
16
  def self.symbolize_keys(hash) #:nodoc:
17
17
  hash.inject({}){|result, (key, value)|
18
18
  new_key = case key
@@ -29,4 +29,4 @@ module MultiJson
29
29
  end
30
30
  end
31
31
  end
32
- end
32
+ end
@@ -9,10 +9,10 @@ module MultiJson
9
9
  opts[:symbolize_names] = options[:symbolize_keys]
10
10
  ::JSON.parse(string, opts)
11
11
  end
12
-
12
+
13
13
  def self.encode(object) #:nodoc:
14
14
  object.to_json
15
15
  end
16
16
  end
17
17
  end
18
- end
18
+ end
@@ -9,10 +9,10 @@ module MultiJson
9
9
  opts[:symbolize_names] = options[:symbolize_keys]
10
10
  ::JSON.parse(string, opts)
11
11
  end
12
-
12
+
13
13
  def self.encode(object) #:nodoc:
14
14
  object.to_json
15
15
  end
16
16
  end
17
17
  end
18
- end
18
+ end
@@ -7,10 +7,10 @@ module MultiJson
7
7
  def self.decode(string, options = {}) #:nodoc:
8
8
  ::Yajl::Parser.new(:symbolize_keys => options[:symbolize_keys]).parse(string)
9
9
  end
10
-
10
+
11
11
  def self.encode(object) #:nodoc:
12
12
  ::Yajl::Encoder.new.encode(object)
13
13
  end
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -0,0 +1,3 @@
1
+ module MultiJson
2
+ VERSION = "0.0.5"
3
+ end
@@ -1,60 +1,27 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/multi_json/version", __FILE__)
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = %q{multi_json}
8
- s.version = "0.0.4"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
5
+ s.name = "multi_json"
6
+ s.version = MultiJson::VERSION
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = ["Michael Bleigh"]
12
- s.date = %q{2010-06-19}
13
9
  s.description = %q{A gem to provide swappable JSON backends utilizing Yajl::Ruby, the JSON gem, ActiveSupport, or JSON pure.}
14
- s.email = %q{michael@intridea.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "Gemfile",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "lib/multi_json.rb",
28
- "lib/multi_json/engines/active_support.rb",
29
- "lib/multi_json/engines/json_gem.rb",
30
- "lib/multi_json/engines/json_pure.rb",
31
- "lib/multi_json/engines/yajl.rb",
32
- "multi_json.gemspec",
33
- "spec/multi_json_spec.rb",
34
- "spec/spec.opts",
35
- "spec/spec_helper.rb"
36
- ]
37
- s.homepage = %q{http://github.com/intridea/multi_json}
10
+ s.summary = %q{A gem to provide swappable JSON backends.}
11
+ s.email = ["michael@intridea.com"]
12
+ s.homepage = "http://github.com/intridea/multi_json"
13
+ s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
38
14
  s.rdoc_options = ["--charset=UTF-8"]
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
39
18
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.6}
41
- s.summary = %q{A gem to provide swappable JSON backends.}
42
- s.test_files = [
43
- "spec/multi_json_spec.rb",
44
- "spec/spec_helper.rb"
45
- ]
46
-
47
- if s.respond_to? :specification_version then
48
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
- s.specification_version = 3
50
-
51
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
53
- else
54
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
55
- end
56
- else
57
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
58
- end
19
+ s.add_development_dependency("rake", "~> 0.8")
20
+ s.add_development_dependency("rcov", "~> 0.9")
21
+ s.add_development_dependency("rspec", "~> 2.0")
22
+ s.add_development_dependency("activesupport", "~> 3.0")
23
+ s.add_development_dependency("json", "~> 1.4")
24
+ s.add_development_dependency("json_pure", "~> 1.4")
25
+ s.add_development_dependency("yajl-ruby", "~> 0.7")
59
26
  end
60
27
 
@@ -4,7 +4,7 @@ class MockDecoder
4
4
  def self.decode(string, options = {})
5
5
  {'abc' => 'def'}
6
6
  end
7
-
7
+
8
8
  def self.encode(string)
9
9
  '{"abc":"def"}'
10
10
  end
@@ -21,13 +21,13 @@ describe "MultiJson" do
21
21
  MultiJson.engine = :yajl
22
22
  MultiJson.engine.name.should == 'MultiJson::Engines::Yajl'
23
23
  end
24
-
24
+
25
25
  it 'should be settable via a class' do
26
26
  MultiJson.engine = MockDecoder
27
27
  MultiJson.engine.name.should == 'MockDecoder'
28
28
  end
29
29
  end
30
-
30
+
31
31
  %w(active_support json_gem json_pure yajl).each do |engine|
32
32
  context engine do
33
33
  before do
@@ -37,7 +37,7 @@ describe "MultiJson" do
37
37
  pending "Engine #{engine} couldn't be loaded (not installed?)"
38
38
  end
39
39
  end
40
-
40
+
41
41
  describe '.encode' do
42
42
  it 'should write decodable JSON' do
43
43
  [
@@ -48,12 +48,18 @@ describe "MultiJson" do
48
48
  end
49
49
  end
50
50
  end
51
-
51
+
52
52
  describe '.decode' do
53
- it 'should properly decode some json' do
53
+ it 'should properly decode valid JSON' do
54
54
  MultiJson.decode('{"abc":"def"}').should == {'abc' => 'def'}
55
55
  end
56
-
56
+
57
+ it 'should raise MultiJson::DecodeError on invalid JSON' do
58
+ lambda do
59
+ MultiJson.decode('{"abc"}')
60
+ end.should raise_error(MultiJson::DecodeError)
61
+ end
62
+
57
63
  it 'should allow for symbolization of keys' do
58
64
  MultiJson.decode('{"abc":{"def":"hgi"}}', :symbolize_keys => true).should == {:abc => {:def => 'hgi'}}
59
65
  end
@@ -1,16 +1,11 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'multi_json'
4
- require 'spec'
5
- require 'spec/autorun'
6
- require 'rubygems'
4
+ require 'rspec'
5
+ require 'rspec/autorun'
7
6
  begin
8
7
  require 'bundler'
9
8
  Bundler.setup
10
9
  rescue LoadError
11
10
  $stderr.puts "Bundler (or a dependency) not available."
12
11
  end
13
-
14
- Spec::Runner.configure do |config|
15
-
16
- end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_json
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 21
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 4
9
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
10
11
  platform: ruby
11
12
  authors:
12
13
  - Michael Bleigh
@@ -14,25 +15,117 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-19 00:00:00 -04:00
18
+ date: 2010-11-04 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- name: rspec
22
+ name: rake
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
- - - ">="
27
+ - - ~>
26
28
  - !ruby/object:Gem::Version
29
+ hash: 27
27
30
  segments:
28
- - 1
29
- - 2
30
- - 9
31
- version: 1.2.9
31
+ - 0
32
+ - 8
33
+ version: "0.8"
32
34
  type: :development
33
35
  version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rcov
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 25
45
+ segments:
46
+ - 0
47
+ - 9
48
+ version: "0.9"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rspec
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 2
62
+ - 0
63
+ version: "2.0"
64
+ type: :development
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: activesupport
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 7
75
+ segments:
76
+ - 3
77
+ - 0
78
+ version: "3.0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: json
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ hash: 7
90
+ segments:
91
+ - 1
92
+ - 4
93
+ version: "1.4"
94
+ type: :development
95
+ version_requirements: *id005
96
+ - !ruby/object:Gem::Dependency
97
+ name: json_pure
98
+ prerelease: false
99
+ requirement: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ hash: 7
105
+ segments:
106
+ - 1
107
+ - 4
108
+ version: "1.4"
109
+ type: :development
110
+ version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ name: yajl-ruby
113
+ prerelease: false
114
+ requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ hash: 5
120
+ segments:
121
+ - 0
122
+ - 7
123
+ version: "0.7"
124
+ type: :development
125
+ version_requirements: *id007
34
126
  description: A gem to provide swappable JSON backends utilizing Yajl::Ruby, the JSON gem, ActiveSupport, or JSON pure.
35
- email: michael@intridea.com
127
+ email:
128
+ - michael@intridea.com
36
129
  executables: []
37
130
 
38
131
  extensions: []
@@ -43,16 +136,18 @@ extra_rdoc_files:
43
136
  files:
44
137
  - .document
45
138
  - .gitignore
139
+ - .rspec
46
140
  - Gemfile
141
+ - Gemfile.lock
47
142
  - LICENSE
48
143
  - README.rdoc
49
144
  - Rakefile
50
- - VERSION
51
145
  - lib/multi_json.rb
52
146
  - lib/multi_json/engines/active_support.rb
53
147
  - lib/multi_json/engines/json_gem.rb
54
148
  - lib/multi_json/engines/json_pure.rb
55
149
  - lib/multi_json/engines/yajl.rb
150
+ - lib/multi_json/version.rb
56
151
  - multi_json.gemspec
57
152
  - spec/multi_json_spec.rb
58
153
  - spec/spec.opts
@@ -67,26 +162,33 @@ rdoc_options:
67
162
  require_paths:
68
163
  - lib
69
164
  required_ruby_version: !ruby/object:Gem::Requirement
165
+ none: false
70
166
  requirements:
71
167
  - - ">="
72
168
  - !ruby/object:Gem::Version
169
+ hash: 3
73
170
  segments:
74
171
  - 0
75
172
  version: "0"
76
173
  required_rubygems_version: !ruby/object:Gem::Requirement
174
+ none: false
77
175
  requirements:
78
176
  - - ">="
79
177
  - !ruby/object:Gem::Version
178
+ hash: 23
80
179
  segments:
81
- - 0
82
- version: "0"
180
+ - 1
181
+ - 3
182
+ - 6
183
+ version: 1.3.6
83
184
  requirements: []
84
185
 
85
186
  rubyforge_project:
86
- rubygems_version: 1.3.6
187
+ rubygems_version: 1.3.7
87
188
  signing_key:
88
189
  specification_version: 3
89
190
  summary: A gem to provide swappable JSON backends.
90
191
  test_files:
91
192
  - spec/multi_json_spec.rb
193
+ - spec/spec.opts
92
194
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.4