DSON 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/DSON.gemspec +25 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/lib/DSON.rb +9 -0
- data/lib/DSON/value.rb +33 -0
- data/lib/DSON/value/array_value.rb +23 -0
- data/lib/DSON/value/false_value.rb +16 -0
- data/lib/DSON/value/hash_value.rb +28 -0
- data/lib/DSON/value/nil_value.rb +17 -0
- data/lib/DSON/value/numeric_value.rb +20 -0
- data/lib/DSON/value/string_value.rb +20 -0
- data/lib/DSON/value/true_value.rb +16 -0
- data/lib/DSON/value/variable_value.rb +14 -0
- data/lib/DSON/version.rb +7 -0
- data/spec/dson_spec.rb +369 -0
- metadata +145 -0
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/DSON.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'DSON/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "DSON"
|
8
|
+
spec.version = DSON::VERSION
|
9
|
+
spec.authors = ["ishakir"]
|
10
|
+
spec.email = ["imran.pshakir@gmail.com"]
|
11
|
+
spec.summary = %q{A pure-ruby DSON Serializer}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "rubocop"
|
24
|
+
spec.add_development_dependency "magic_encoding"
|
25
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ishakir
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# DSON
|
2
|
+
|
3
|
+
Such serialization! Totally pure-ruby also completely DSON. Wow!
|
4
|
+
|
5
|
+
Currently known deficiencies:
|
6
|
+
* Number handling (needs to be octal, currently treated as string)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'DSON'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install DSON
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Currently supports a ruby hash and array data structure and outputs it's representation in DSON ([Doge Serialized Object notation](http://dogeon.org/)). By way of an example, try:
|
25
|
+
|
26
|
+
require 'DSON'
|
27
|
+
|
28
|
+
puts DSON.such_serialize_wow({
|
29
|
+
ruby: 'pure',
|
30
|
+
supports: [
|
31
|
+
'hash',
|
32
|
+
'array'
|
33
|
+
]
|
34
|
+
})
|
35
|
+
|
36
|
+
This should output:
|
37
|
+
|
38
|
+
such "ruby" is "pure", "supports" is so "hash" also "array" many wow
|
39
|
+
|
40
|
+
Correct to the DSON spec
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( https://github.com/[my-github-username]/DSON/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/DSON.rb
ADDED
data/lib/DSON/value.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value/hash_value'
|
3
|
+
require 'DSON/value/array_value'
|
4
|
+
require 'DSON/value/string_value'
|
5
|
+
require 'DSON/value/nil_value'
|
6
|
+
require 'DSON/value/true_value'
|
7
|
+
require 'DSON/value/false_value'
|
8
|
+
require 'DSON/value/numeric_value'
|
9
|
+
|
10
|
+
module DSON
|
11
|
+
module Value
|
12
|
+
SPACE = %q( )
|
13
|
+
|
14
|
+
def self.new(value)
|
15
|
+
return HashValue.new(value) if value.respond_to? :keys
|
16
|
+
return ArrayValue.new(value) if value.respond_to? :each
|
17
|
+
return NilValue.instance if value.nil?
|
18
|
+
return TrueValue.instance if value.is_a? TrueClass
|
19
|
+
return FalseValue.instance if value.is_a? FalseClass
|
20
|
+
#return NumericValue.new(value) if value.is_a? Fixnum
|
21
|
+
StringValue.new(value)
|
22
|
+
end
|
23
|
+
|
24
|
+
def reduce(list, potential_joiners)
|
25
|
+
list.each_with_index.reduce('') do |acc, (element, index)|
|
26
|
+
is_last = (index == list.size - 1)
|
27
|
+
|
28
|
+
formed_string = is_last ? element : element + potential_joiners.sample
|
29
|
+
acc + formed_string + SPACE
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module DSON
|
3
|
+
module Value
|
4
|
+
class ArrayValue
|
5
|
+
include Value
|
6
|
+
|
7
|
+
POTENTIAL_JOINERS = [' and' , ' also']
|
8
|
+
|
9
|
+
attr_reader :value
|
10
|
+
|
11
|
+
def initialize(value)
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def such_serialize_wow
|
16
|
+
content = value.map do |arr_elem|
|
17
|
+
Value.new(arr_elem).such_serialize_wow
|
18
|
+
end
|
19
|
+
'so ' + reduce(content, POTENTIAL_JOINERS) + 'many'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value'
|
3
|
+
|
4
|
+
module DSON
|
5
|
+
module Value
|
6
|
+
class HashValue
|
7
|
+
include Value
|
8
|
+
|
9
|
+
POTENTIAL_PUNCTUATION = %w(, . ! ?)
|
10
|
+
|
11
|
+
attr_reader :value
|
12
|
+
|
13
|
+
def initialize(value)
|
14
|
+
@value = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def such_serialize_wow
|
18
|
+
strings = value.keys.map do |key|
|
19
|
+
key_str = StringValue.new(key).such_serialize_wow
|
20
|
+
value_str = Value.new(value[key]).such_serialize_wow
|
21
|
+
|
22
|
+
%Q(#{key_str} is #{value_str})
|
23
|
+
end
|
24
|
+
'such ' + reduce(strings, POTENTIAL_PUNCTUATION) + 'wow'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value'
|
3
|
+
|
4
|
+
module DSON
|
5
|
+
module Value
|
6
|
+
class NumericValue
|
7
|
+
include Value
|
8
|
+
|
9
|
+
attr_reader :value
|
10
|
+
|
11
|
+
def initialize(value)
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def such_serialize_wow
|
16
|
+
value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value'
|
3
|
+
|
4
|
+
module DSON
|
5
|
+
module Value
|
6
|
+
class StringValue
|
7
|
+
include Value
|
8
|
+
|
9
|
+
attr_reader :value
|
10
|
+
|
11
|
+
def initialize(value)
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def such_serialize_wow
|
16
|
+
"\"#{value}\""
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/DSON/version.rb
ADDED
data/spec/dson_spec.rb
ADDED
@@ -0,0 +1,369 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON'
|
3
|
+
|
4
|
+
PUNCTUATION_MATCH = '(,|\.|!|\\?)'
|
5
|
+
AND_MATCH = '(and|also)'
|
6
|
+
|
7
|
+
describe 'DSON simple hash handling' do
|
8
|
+
|
9
|
+
it 'should be correct with an empty hash' do
|
10
|
+
dson_hash = Hash.new
|
11
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
12
|
+
|
13
|
+
expect(dson_string).to eq(
|
14
|
+
'such wow'
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should be correct with a hash with one element' do
|
19
|
+
dson_hash = {
|
20
|
+
dson: 'awesome'
|
21
|
+
}
|
22
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
23
|
+
|
24
|
+
expect(dson_string).to eq(
|
25
|
+
'such "dson" is "awesome" wow'
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should be correct with a hash with two elements' do
|
30
|
+
dson_or_ruby = '("dson" is "awesome"|"ruby" is "great")'
|
31
|
+
|
32
|
+
dson_hash = {
|
33
|
+
dson: 'awesome',
|
34
|
+
ruby: 'great'
|
35
|
+
}
|
36
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
37
|
+
|
38
|
+
expect(dson_string).to match(
|
39
|
+
/such #{dson_or_ruby}#{PUNCTUATION_MATCH} #{dson_or_ruby} wow/
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should be correct with a hash with three elements' do
|
44
|
+
dson_ruby_or_dogescript =
|
45
|
+
'(' \
|
46
|
+
'"dson" is "awesome"' \
|
47
|
+
'|' \
|
48
|
+
'"ruby" is "great"' \
|
49
|
+
'|' \
|
50
|
+
'"dogescript" is "fine"' \
|
51
|
+
')'
|
52
|
+
|
53
|
+
dson_hash = {
|
54
|
+
dson: 'awesome',
|
55
|
+
ruby: 'great',
|
56
|
+
dogescript: 'fine'
|
57
|
+
}
|
58
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
59
|
+
|
60
|
+
regex_string =
|
61
|
+
'such' \
|
62
|
+
' ' +
|
63
|
+
dson_ruby_or_dogescript +
|
64
|
+
PUNCTUATION_MATCH +
|
65
|
+
' ' +
|
66
|
+
dson_ruby_or_dogescript +
|
67
|
+
PUNCTUATION_MATCH +
|
68
|
+
' ' +
|
69
|
+
dson_ruby_or_dogescript +
|
70
|
+
' ' +
|
71
|
+
'wow'
|
72
|
+
|
73
|
+
expect(dson_string).to match(
|
74
|
+
/#{regex_string}/
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'DSON simple array handling' do
|
81
|
+
|
82
|
+
it 'should correctly handle an empty array' do
|
83
|
+
dson_array = Array.new
|
84
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
85
|
+
|
86
|
+
expect(dson_string).to eq(
|
87
|
+
'so many'
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should correctly handle an array with a single element' do
|
92
|
+
dson_array = %w(cheese)
|
93
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
94
|
+
|
95
|
+
expect(dson_string).to eq(
|
96
|
+
'so "cheese" many'
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should correctly handle an array with two elements' do
|
101
|
+
dson_array = %w(cheese wine)
|
102
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
103
|
+
|
104
|
+
expect(dson_string).to match(
|
105
|
+
/so "cheese" #{AND_MATCH} "wine" many/
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should correctly handle an array with three elements' do
|
110
|
+
dson_array = %w(cheese wine bread)
|
111
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
112
|
+
|
113
|
+
expect(dson_string).to match(
|
114
|
+
/so "cheese" #{AND_MATCH} "wine" #{AND_MATCH} "bread" many/
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'DSON nested arrays' do
|
121
|
+
|
122
|
+
it 'should correctly handle empty nested arrays' do
|
123
|
+
dson_array = [[]]
|
124
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
125
|
+
|
126
|
+
expect(dson_string).to eq(
|
127
|
+
'so so many many'
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should correctly handle nested arrays with elements' do
|
132
|
+
dson_array = ['cheese', []]
|
133
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
134
|
+
|
135
|
+
expect(dson_string).to match(
|
136
|
+
/so "cheese" #{AND_MATCH} so many many/
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should correctly handle a nested array with an element' do
|
141
|
+
dson_array = [['cheese']]
|
142
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
143
|
+
|
144
|
+
expect(dson_string).to eq(
|
145
|
+
'so so "cheese" many many'
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should correctly handle a more complex nested array' do
|
150
|
+
dson_array = ['cheese', ['cheese', ['cheese']]]
|
151
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
152
|
+
|
153
|
+
expect(dson_string).to match(
|
154
|
+
/so "cheese" #{AND_MATCH} so "cheese" #{AND_MATCH} so "cheese" many many many/
|
155
|
+
)
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
describe 'DSON nested hashes' do
|
161
|
+
|
162
|
+
it 'should handle a simple nested hash' do
|
163
|
+
dson_hash = {
|
164
|
+
nested: {}
|
165
|
+
}
|
166
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
167
|
+
|
168
|
+
expect(dson_string).to eq(
|
169
|
+
'such "nested" is such wow wow'
|
170
|
+
)
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should handle a further nested hash' do
|
174
|
+
dson_hash = {
|
175
|
+
nested: {
|
176
|
+
further_nested: {
|
177
|
+
}
|
178
|
+
}
|
179
|
+
}
|
180
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
181
|
+
|
182
|
+
expect(dson_string).to eq(
|
183
|
+
'such "nested" is such "further_nested" is such wow wow wow'
|
184
|
+
)
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should handle other elements in this hash' do
|
188
|
+
dson_hash = {
|
189
|
+
other: 'true',
|
190
|
+
nested: {
|
191
|
+
}
|
192
|
+
}
|
193
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
194
|
+
|
195
|
+
other_or_nested = '("other" is "true"|"nested" is such wow)'
|
196
|
+
|
197
|
+
expect(dson_string).to match(
|
198
|
+
/such #{other_or_nested}#{PUNCTUATION_MATCH} #{other_or_nested} wow/
|
199
|
+
)
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should handle elements in a nested hash' do
|
203
|
+
dson_hash = {
|
204
|
+
other: 'true',
|
205
|
+
nested: {
|
206
|
+
element: 'great'
|
207
|
+
}
|
208
|
+
}
|
209
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
210
|
+
|
211
|
+
other_or_nested = '("other" is "true"|"nested" is such "element" is "great" wow)'
|
212
|
+
|
213
|
+
expect(dson_string).to match(
|
214
|
+
/such #{other_or_nested}#{PUNCTUATION_MATCH} #{other_or_nested} wow/
|
215
|
+
)
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'should handle multiple elements in the nested hash' do
|
219
|
+
dson_hash = {
|
220
|
+
wine: {
|
221
|
+
white: 'great',
|
222
|
+
red: 'greater'
|
223
|
+
}
|
224
|
+
}
|
225
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
226
|
+
|
227
|
+
white_or_red = '("white" is "great"|"red" is "greater")'
|
228
|
+
|
229
|
+
expect(dson_string).to match(
|
230
|
+
/such "wine" is such #{white_or_red}#{PUNCTUATION_MATCH} #{white_or_red} wow wow/
|
231
|
+
)
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
describe 'DSON hash and array mixes' do
|
237
|
+
|
238
|
+
it 'should handle an array of empty objects' do
|
239
|
+
dson_array = [
|
240
|
+
{}, {}
|
241
|
+
]
|
242
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
243
|
+
|
244
|
+
expect(dson_string).to match(
|
245
|
+
/so such wow #{AND_MATCH} such wow many/
|
246
|
+
)
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'should handle an object with an empty array element' do
|
250
|
+
dson_hash = {
|
251
|
+
array: []
|
252
|
+
}
|
253
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
254
|
+
|
255
|
+
expect(dson_string).to eq(
|
256
|
+
'such "array" is so many wow'
|
257
|
+
)
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'should handle an object with an array element' do
|
261
|
+
dson_hash = {
|
262
|
+
array: [
|
263
|
+
'olive',
|
264
|
+
'grape'
|
265
|
+
]
|
266
|
+
}
|
267
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
268
|
+
|
269
|
+
expect(dson_string).to match(
|
270
|
+
/such "array" is so "olive" #{AND_MATCH} "grape" many wow/
|
271
|
+
)
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'should handle an array with an object element' do
|
275
|
+
dson_array = [
|
276
|
+
{
|
277
|
+
first_name: 'Cyril',
|
278
|
+
surname: 'Figgis'
|
279
|
+
}
|
280
|
+
]
|
281
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
282
|
+
|
283
|
+
first_or_last_name = '("first_name" is "Cyril"|"surname" is "Figgis")'
|
284
|
+
|
285
|
+
expect(dson_string).to match(
|
286
|
+
/so such #{first_or_last_name}#{PUNCTUATION_MATCH} #{first_or_last_name} wow many/
|
287
|
+
)
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
describe "DSON empty" do
|
293
|
+
|
294
|
+
it "translates a nil object to empty" do
|
295
|
+
dson_hash = {
|
296
|
+
value: nil
|
297
|
+
}
|
298
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
299
|
+
|
300
|
+
expect(dson_string).to eq(
|
301
|
+
'such "value" is empty wow'
|
302
|
+
)
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
describe "DSON booleans" do
|
308
|
+
|
309
|
+
it "translates a true object to yes" do
|
310
|
+
dson_hash = {
|
311
|
+
value: true
|
312
|
+
}
|
313
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
314
|
+
|
315
|
+
expect(dson_string).to eq(
|
316
|
+
'such "value" is yes wow'
|
317
|
+
)
|
318
|
+
end
|
319
|
+
|
320
|
+
it "translates a false object to no" do
|
321
|
+
dson_hash = {
|
322
|
+
value: false
|
323
|
+
}
|
324
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
325
|
+
|
326
|
+
expect(dson_string).to eq(
|
327
|
+
'such "value" is no wow'
|
328
|
+
)
|
329
|
+
end
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
#TODO fix when we can do octals generically
|
334
|
+
# describe "DSON numbers" do
|
335
|
+
|
336
|
+
# it "doesn't quote numeric values" do
|
337
|
+
# dson_hash = {
|
338
|
+
# value: 13
|
339
|
+
# }
|
340
|
+
# dson_string = DSON.such_serialize_wow(dson_hash)
|
341
|
+
|
342
|
+
# expect(dson_string).to eq(
|
343
|
+
# 'such "value" is 13 wow'
|
344
|
+
# )
|
345
|
+
# end
|
346
|
+
|
347
|
+
# it "quotes numeric values represented as strings" do
|
348
|
+
# dson_hash = {
|
349
|
+
# value: "13"
|
350
|
+
# }
|
351
|
+
# dson_string = DSON.such_serialize_wow(dson_hash)
|
352
|
+
|
353
|
+
# expect(dson_string).to eq(
|
354
|
+
# 'such "value" is "13" wow'
|
355
|
+
# )
|
356
|
+
# end
|
357
|
+
|
358
|
+
# it "quotes float values" do
|
359
|
+
# dson_hash = {
|
360
|
+
# value: 12.5
|
361
|
+
# }
|
362
|
+
# dson_string = DSON.such_serialize_wow(dson_hash)
|
363
|
+
|
364
|
+
# expect(dson_string).to eq(
|
365
|
+
# 'such "value" is 12.5 wow'
|
366
|
+
# )
|
367
|
+
# end
|
368
|
+
|
369
|
+
# end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: DSON
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ishakir
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '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'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rubocop
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '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: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: magic_encoding
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description:
|
95
|
+
email:
|
96
|
+
- imran.pshakir@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- DSON.gemspec
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/DSON.rb
|
108
|
+
- lib/DSON/value.rb
|
109
|
+
- lib/DSON/value/array_value.rb
|
110
|
+
- lib/DSON/value/false_value.rb
|
111
|
+
- lib/DSON/value/hash_value.rb
|
112
|
+
- lib/DSON/value/nil_value.rb
|
113
|
+
- lib/DSON/value/numeric_value.rb
|
114
|
+
- lib/DSON/value/string_value.rb
|
115
|
+
- lib/DSON/value/true_value.rb
|
116
|
+
- lib/DSON/value/variable_value.rb
|
117
|
+
- lib/DSON/version.rb
|
118
|
+
- spec/dson_spec.rb
|
119
|
+
homepage: ''
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.8.24
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: A pure-ruby DSON Serializer
|
144
|
+
test_files:
|
145
|
+
- spec/dson_spec.rb
|