json_builder 2.0.1 → 2.0.2
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.
- data/README.md +4 -0
- data/lib/json_builder.rb +1 -4
- data/lib/json_builder/generator.rb +15 -3
- data/lib/json_builder/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -71,6 +71,10 @@ You will get something like:
|
|
71
71
|
|
72
72
|
puts json.compile!
|
73
73
|
|
74
|
+
## Conversions
|
75
|
+
|
76
|
+
Time - [ISO-8601](http://en.wikipedia.org/wiki/ISO_8601)
|
77
|
+
|
74
78
|
## Speed
|
75
79
|
JSON Builder is very fast, it's roughly 6 times faster than the core XML Builder based on the [speed benchmark](http://github.com/dewski/json_builder/blob/master/test/benchmarks/speed.rb).
|
76
80
|
|
data/lib/json_builder.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'blankslate' unless defined?
|
2
|
+
require 'blankslate' unless defined? BlankSlate
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
module JSONBuilder
|
@@ -17,6 +17,11 @@ module JSONBuilder
|
|
17
17
|
compile!
|
18
18
|
end
|
19
19
|
|
20
|
+
#
|
21
|
+
# Using +tag!+ is neccessary when dynamic keys are needed
|
22
|
+
#
|
23
|
+
# json.tag!
|
24
|
+
#
|
20
25
|
def tag!(sym, *args, &block)
|
21
26
|
method_missing(sym.to_sym, *args, &block)
|
22
27
|
end
|
@@ -52,8 +57,15 @@ module JSONBuilder
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def compile!
|
60
|
+
# If there is no JSON, no need for an array
|
55
61
|
if @is_array
|
56
|
-
|
62
|
+
if @compiled.length > 0
|
63
|
+
compiled = ('[{' + @compiled.join(',') + '}]').gsub(',},{,', '},{')
|
64
|
+
else
|
65
|
+
# No need to make this pretty
|
66
|
+
@pretty_print = false
|
67
|
+
compiled = '[]'
|
68
|
+
end
|
57
69
|
else
|
58
70
|
compiled = '{' + @compiled.join(', ') + '}'
|
59
71
|
end
|
@@ -75,7 +87,7 @@ module JSONBuilder
|
|
75
87
|
when TrueClass then 'true'
|
76
88
|
when FalseClass then 'false'
|
77
89
|
when NilClass then 'null'
|
78
|
-
when DateTime, Time, Date then "\"#{text.strftime(
|
90
|
+
when DateTime, Time, Date then "\"#{text.strftime('%Y-%m-%dT%H:%M:%S%z')}\""
|
79
91
|
when Fixnum then text
|
80
92
|
end
|
81
93
|
end
|
data/lib/json_builder/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 2
|
10
|
+
version: 2.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Garrett Bjerkhoel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-31 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|