protojson 0.1.0 → 0.2.0

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,85 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'protojson'
4
+
5
+ describe Protojson do
6
+
7
+ context "initialize with default behavior" do
8
+
9
+ it "should have the default codecs when initialized" do
10
+ Protojson.codecs.length.should eql(5)
11
+ end
12
+
13
+ it 'should get a default codec if none set' do
14
+ codec = Protojson[]
15
+ codec.should be_a_kind_of Protojson::Codec::CodecInterface
16
+ end
17
+
18
+ end
19
+ context "getting codecs" do
20
+
21
+ it 'should return the passed codec instance' do
22
+ passed = Protojson::Codec::Binary
23
+ getted = Protojson[passed]
24
+ passed.should eql getted
25
+ end
26
+
27
+ it 'should return the codec mapped to the attribute' do
28
+ setted = Protojson::Codec::Binary
29
+ Protojson[:test] = setted
30
+ getted = Protojson[:test]
31
+ getted.should be(Protojson::Codec::Binary)
32
+ end
33
+
34
+ it 'should raise an exception if the codec does not exist' do
35
+ lambda { Protojson[:foo] }.should raise_error(Exception)
36
+ end
37
+
38
+ end
39
+
40
+ context "setting codecs" do
41
+
42
+ it 'should register a new codec' do
43
+ setted = Protojson::Codec::Binary
44
+ Protojson[:test] = setted
45
+ getted = Protojson[:test]
46
+ getted.should eql setted
47
+ end
48
+
49
+ it 'should register a new default codec with parameter type of Codec' do
50
+ setted = Protojson::Codec::Binary
51
+ Protojson.set_default_codec(setted)
52
+ Protojson[].should eql setted
53
+ end
54
+
55
+ it 'should register a new default codec with parameter type of string' do
56
+ setted = Protojson::Codec::Binary
57
+ Protojson[:foo] = setted
58
+ Protojson.set_default_codec(:foo)
59
+ Protojson[].should eql setted
60
+ end
61
+
62
+ it 'should throw an exception while registering a codec that does not implement the Codec interface' do
63
+ lambda { Protojson[:test] = :foo }.should raise_error(Exception)
64
+ end
65
+ end
66
+
67
+ context "unsetting codecs" do
68
+
69
+ it 'should unregister an existing codec' do
70
+ setted = Protojson::Codec::Binary
71
+ Protojson[:test] = setted
72
+ getted = Protojson[:test]
73
+ getted.should eql setted
74
+ Protojson[:test] = nil
75
+ lambda { Protojson[:test] }.should raise_error(Exception)
76
+ end
77
+
78
+ it "should unregister the default codec" do
79
+ Protojson[] = nil
80
+ getted = Protojson[]
81
+ getted.should be_a_kind_of Protojson::Codec::CodecInterface
82
+ getted.should be Protojson::Codec::Binary
83
+ end
84
+ end
85
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protojson
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 0
9
- version: 0.1.0
4
+ prerelease:
5
+ version: 0.2.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Juan de Bravo
@@ -15,10 +11,53 @@ autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
13
 
18
- date: 2011-03-28 00:00:00 +02:00
14
+ date: 2011-08-20 00:00:00 +03:00
19
15
  default_executable:
20
- dependencies: []
21
-
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: ruby_protobuf
19
+ prerelease: false
20
+ requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: 0.4.10
26
+ type: :runtime
27
+ version_requirements: *id001
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ prerelease: false
31
+ requirement: &id002 !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: 3.0.5
37
+ type: :runtime
38
+ version_requirements: *id002
39
+ - !ruby/object:Gem::Dependency
40
+ name: i18n
41
+ prerelease: false
42
+ requirement: &id003 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.0
48
+ type: :runtime
49
+ version_requirements: *id003
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ prerelease: false
53
+ requirement: &id004 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ type: :development
60
+ version_requirements: *id004
22
61
  description: |-
23
62
  A Ruby gem for Google's Protocol Buffers messages using three different encodings JSON
24
63
  based syntax instead of the original binary protocol. Supported formats
@@ -46,13 +85,32 @@ files:
46
85
  - LICENSE
47
86
  - README.md
48
87
  - Rakefile
88
+ - examples/addressbook.pb.rb
89
+ - examples/addressbook.proto
90
+ - examples/addressbook2.pb.rb
91
+ - examples/example.rb
92
+ - examples/main.rb
93
+ - examples/person
94
+ - examples/repeated.pb.rb
95
+ - examples/repeated.proto
96
+ - examples/simple.pb.rb
97
+ - examples/simple.proto
49
98
  - lib/extensions/protobuf/message.rb
50
99
  - lib/protojson.rb
100
+ - lib/protojson/codec/binary.rb
101
+ - lib/protojson/codec/codec_interface.rb
102
+ - lib/protojson/codec/hash.rb
103
+ - lib/protojson/codec/json.rb
104
+ - lib/protojson/codec/json_indexed.rb
105
+ - lib/protojson/codec/json_tag_map.rb
51
106
  - lib/protojson/version.rb
52
107
  - protojson.gemspec
53
108
  - spec/addressbook.pb.rb
54
- - spec/main.rb
55
- - spec/person
109
+ - spec/codec_binary_spec.rb
110
+ - spec/codec_json_hash_tag_spec.rb
111
+ - spec/codec_json_indexed_spec.rb
112
+ - spec/codec_json_spec.rb
113
+ - spec/codecs_registry_spec.rb
56
114
  has_rdoc: true
57
115
  homepage: ""
58
116
  licenses: []
@@ -67,25 +125,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
125
  requirements:
68
126
  - - ">="
69
127
  - !ruby/object:Gem::Version
70
- segments:
71
- - 0
72
128
  version: "0"
73
129
  required_rubygems_version: !ruby/object:Gem::Requirement
74
130
  none: false
75
131
  requirements:
76
132
  - - ">="
77
133
  - !ruby/object:Gem::Version
78
- segments:
79
- - 0
80
134
  version: "0"
81
135
  requirements: []
82
136
 
83
137
  rubyforge_project: protojson
84
- rubygems_version: 1.3.7
138
+ rubygems_version: 1.6.2
85
139
  signing_key:
86
140
  specification_version: 3
87
141
  summary: Ruby extension to ruby-protobuf to enable three new encodings
88
142
  test_files:
89
143
  - spec/addressbook.pb.rb
90
- - spec/main.rb
91
- - spec/person
144
+ - spec/codec_binary_spec.rb
145
+ - spec/codec_json_hash_tag_spec.rb
146
+ - spec/codec_json_indexed_spec.rb
147
+ - spec/codec_json_spec.rb
148
+ - spec/codecs_registry_spec.rb
data/spec/main.rb DELETED
@@ -1,55 +0,0 @@
1
-
2
- $:.unshift File.join(File.dirname(__FILE__),'..','lib')
3
- $:.unshift File.join(File.dirname(__FILE__),'.')
4
-
5
- require 'rubygems'
6
- require 'addressbook.pb'
7
- require 'protojson'
8
-
9
- unless ARGV.size == 1
10
- puts "Usage: #{$0} ADDRESS_BOOK_FILE"
11
- exit
12
- end
13
-
14
- person = Tutorial::Person.new
15
- person.parse_from_file ARGV[0]
16
-
17
- puts ""
18
- puts "Person data"
19
- puts "..........."
20
- p person
21
-
22
- Protobuf::Message::encoding = Protobuf::Message::EncodingType::INDEXED
23
-
24
- value = person.serialize_to_string
25
-
26
- puts ""
27
- puts "Indexed encoding"
28
- puts "................"
29
- puts value
30
-
31
- Protobuf::Message::encoding = Protobuf::Message::EncodingType::TAGMAP
32
-
33
- value = person.serialize_to_string
34
-
35
- puts ""
36
- puts "Tagmap encoding"
37
- puts "..............."
38
- puts value
39
-
40
- Protobuf::Message::encoding = Protobuf::Message::EncodingType::HASHMAP
41
-
42
- value = person.serialize_to_string
43
-
44
- puts ""
45
- puts "Hashmap encoding"
46
- puts "................"
47
- puts value
48
- puts ""
49
-
50
- #Protobuf::Message::encoding = Protobuf::Message::EncodingType::BINARY
51
-
52
- #value = person.serialize_to_string
53
-
54
- #puts value
55
-