asir_json 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color -f d
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - jruby-18mode
6
+ - jruby-19mode
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - ruby-head
10
+ - jruby-head
11
+ - 1.8.7
12
+ - ree
@@ -0,0 +1,6 @@
1
+ 2012-12-29 Kurt A. Stephens <ks.github@kurtstephens.com>
2
+
3
+ * v1.1.11: New version.
4
+ * ASIR: Moved ASIR::Coder::JSON to gem asir_json.
5
+
6
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asir_json.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kurt Stephens
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # asir_json
2
+
3
+ JSON Coder for ASIR
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'asir_json'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install asir_json
18
+
19
+ ## Usage
20
+
21
+ See spec/.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,26 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ gem 'rspec'
4
+ require 'rspec/core/rake_task'
5
+
6
+ ######################################################################
7
+
8
+ desc "Default => :test"
9
+ task :default => :test
10
+
11
+ desc "Run all tests"
12
+ task :test => [ :spec ]
13
+
14
+ desc "Run specs"
15
+ RSpec::Core::RakeTask.new(:spec) do |t|
16
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
17
+ # Put spec opts in a file named .rspec in root
18
+ end
19
+
20
+ desc "Generate code coverage"
21
+ RSpec::Core::RakeTask.new(:coverage) do |t|
22
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
23
+ t.rcov = true
24
+ t.rcov_opts = ['--exclude', 'spec']
25
+ end
26
+
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asir_json/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "asir_json"
8
+ gem.version = AsirJson::VERSION
9
+ gem.authors = ["Kurt Stephens"]
10
+ gem.email = ["kurt@enova.com"]
11
+ gem.description = %q{JSON Coder for ASIR}
12
+ gem.summary = %q{JSON Coder for ASIR}
13
+ gem.homepage = "http://github.com/kstephens/abstracting_services_in_ruby"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "asir", ">= 1.1.10"
21
+ gem.add_dependency "json", ">= 1.5.3"
22
+
23
+ gem.add_development_dependency 'rake', '>= 0.9.0'
24
+ gem.add_development_dependency 'rspec', '~> 2.12.0'
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'asir'
2
+
3
+ module ASIR
4
+ class Coder
5
+ # !SLIDE
6
+ # JSON Coder
7
+ #
8
+ # Note: Symbols are not handled.
9
+ # The actual JSON expression is wrapped with an Array.
10
+ class JSON < self
11
+ def _encode obj
12
+ [ obj ].to_json
13
+ end
14
+
15
+ def _decode obj
16
+ ::JSON.parser.new(obj).
17
+ parse.first
18
+ end
19
+ end
20
+ # !SLIDE END
21
+ end
22
+ end
23
+
24
+ if RUBY_PLATFORM =~ /java/
25
+ require 'json'
26
+ else
27
+ require 'json/ext'
28
+ end
29
+
@@ -0,0 +1,5 @@
1
+ require "asir_json/version"
2
+
3
+ module AsirJson
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module AsirJson
2
+ VERSION = "1.1.11"
3
+ end
@@ -0,0 +1,140 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'asir/coder/json'
3
+
4
+ describe "ASIR::Coder::JSON" do
5
+ before(:each) do
6
+ @enc = ASIR::Coder::JSON.new
7
+ @dec = @enc.dup
8
+ end
9
+
10
+ basic_objs = [ ]
11
+
12
+ [
13
+ [ nil, 'null' ],
14
+ true,
15
+ false,
16
+ ].each do | x |
17
+ x, str = *x
18
+ str ||= x.inspect
19
+ str = "[#{str}]"
20
+ basic_objs << [ x, str ]
21
+ it "should handle #{x.inspect}" do
22
+ out = @enc.prepare.encode(x)
23
+ out.should == str
24
+ @dec.prepare.decode(out).should == x
25
+ end
26
+ end
27
+
28
+ [
29
+ 1234,
30
+ 1.234,
31
+ [ :symbol, '"symbol"' ],
32
+ ].each do | x |
33
+ x, str = *x
34
+ str ||= x.inspect
35
+ str = "[#{str}]"
36
+ basic_objs << [ x, str ]
37
+ it "should handle #{x.inspect}" do
38
+ out = @enc.prepare.encode(x)
39
+ out.should == str
40
+ y = @dec.prepare.decode(out)
41
+ y = y.to_sym if Symbol === x
42
+ y.should == x
43
+ end
44
+ end
45
+
46
+ [
47
+ 'String',
48
+ ].each do | x |
49
+ x, str = *x
50
+ str ||= x.inspect
51
+ str = "[#{str}]"
52
+ basic_objs << [ x, str ]
53
+ it "should handle #{x.inspect}" do
54
+ out = @enc.prepare.encode(x)
55
+ out.should == str
56
+ y = @dec.prepare.decode(out)
57
+ y.should == x
58
+ end
59
+ end
60
+
61
+ it "should handle empty Array" do
62
+ x = [ ]
63
+ out = @enc.prepare.encode(x)
64
+ out.should == "[[]]"
65
+ @dec.prepare.decode(out).should == x
66
+ end
67
+
68
+ it "should handle Array" do
69
+ x = basic_objs.map{|e| e[0]}
70
+ out = @enc.encode(x)
71
+ out.should == "[[null,true,false,1234,1.234,\"symbol\",\"String\"]]"
72
+ y = @dec.decode(out)
73
+ y.should == x.map{|e| Symbol === e ? e.to_s : e }
74
+ end
75
+
76
+ it "should handle empty Hash" do
77
+ x = { }
78
+ out = @enc.encode(x)
79
+ out.should == "[{}]"
80
+ @dec.decode(out).should == x
81
+ end
82
+
83
+ it "should handle Hash" do
84
+ x = Hash[ *basic_objs.flatten.reverse ]
85
+ out = @enc.prepare.encode(x)
86
+ out.should =~ %r{\A\[\{}
87
+ out.should =~ %r{\}\]\Z}
88
+ basic_objs.each do | v, str |
89
+ # out.should =~ %r{#{k.inspect}:}
90
+ out.should =~ %r{#{str}}
91
+ end
92
+ y = @dec.prepare.decode(out)
93
+ y.should == x.inject({}){|h, (k, v)| h[k] = Symbol === v ? v.to_s : v; h }
94
+ end
95
+
96
+ module ASIR::Coder::Test
97
+ class Object
98
+ attr_accessor :a, :h, :o
99
+ end
100
+ end
101
+
102
+ it "should handle deep objects" do
103
+ x = ASIR::Coder::Test::Object.new
104
+ x.a = [ *basic_objs.map{|a| a[0]} ]
105
+ x.h = Hash[ *basic_objs.flatten.reverse ]
106
+ x.o = ASIR::Coder::Test::Object.new
107
+ x.o.a = 123
108
+ out = @enc.prepare.encode(x)
109
+ if out =~ %r{#<ASIR::Coder::Test::Object}
110
+ out.should =~ %r{\A\[\"#<ASIR::Coder::Test::Object:[^>]+>\"\]\Z}
111
+ else
112
+ out.should =~ %r{"a":\[null,true,false,1234,1.234,"symbol","String"\]}
113
+ out.should =~ %r{"h":\{}
114
+ out.should =~ %r{"\[1234\]":1234}
115
+ out.should =~ %r{"\[1.234\]":1.234}
116
+ out.should =~ %r{"\[null\]":null}
117
+ out.should =~ %r{"\[\\"String\\"\]":"String"}
118
+ out.should =~ %r{"\[\\"symbol\\"\]":"symbol"}
119
+ out.should =~ %r{"\[null\]":null}
120
+ out.should =~ %r{"\[true\]":true}
121
+ out.should =~ %r{"\[null\]":null}
122
+ end
123
+
124
+ # FIXME:
125
+ #out.should =~ %r{<#{x.class.name.gsub('::', '.')} id=\"#{x.object_id}\" >}
126
+ #out.should =~ %r{</#{x.class.name.gsub('::', '.')}>}
127
+ y = @dec.prepare.decode(out)
128
+ (String === y).should == true
129
+ =begin
130
+ FIXME:
131
+ y.a.should == x.a
132
+ y.h.should == x.h
133
+ y.o.class.should == ASIR::Coder::Test::Object
134
+ y.o.a.should == x.o.a
135
+ x.instance_variables.sort { | a, b | a.to_s <=> b.to_s }.should ==
136
+ y.instance_variables.sort { | a, b | a.to_s <=> b.to_s }
137
+ =end
138
+ end
139
+ end
140
+
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ if p = ENV['ASIR_LIB_PATH']
5
+ $:.unshift File.expand_path(p)
6
+ else
7
+ gem 'asir'
8
+ end
9
+ require 'asir'
10
+ require 'asir/coder/json'
11
+
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asir_json
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.11
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kurt Stephens
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: asir
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.10
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.10
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.5.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.5.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.12.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.0
78
+ description: JSON Coder for ASIR
79
+ email:
80
+ - kurt@enova.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - .travis.yml
88
+ - ChangeLog
89
+ - Gemfile
90
+ - LICENSE.txt
91
+ - README.md
92
+ - Rakefile
93
+ - asir_json.gemspec
94
+ - lib/asir/coder/json.rb
95
+ - lib/asir_json.rb
96
+ - lib/asir_json/version.rb
97
+ - spec/json_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: http://github.com/kstephens/abstracting_services_in_ruby
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ segments:
112
+ - 0
113
+ hash: 3189383206848906743
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ segments:
121
+ - 0
122
+ hash: 3189383206848906743
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 1.8.24
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: JSON Coder for ASIR
129
+ test_files:
130
+ - spec/json_spec.rb
131
+ - spec/spec_helper.rb