rmtools 1.2.10b → 1.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +1 -0
- data/Rakefile +1 -1
- data/lib/rmtools/conversions/json.rb +54 -35
- metadata +7 -10
data/README.txt
CHANGED
@@ -12,6 +12,7 @@ Methods for basic classes addon collection.
|
|
12
12
|
|
13
13
|
* Update String#parse:caller to parse ruby 1.9 "block level". Now block level processes in RMLogger and RMTools.format_trace
|
14
14
|
* lib/dev/traceback.rb now applies to ruby > 1.9 as well
|
15
|
+
* Support of Yajl or (if not installed) JSON for #to_json and #from_json. Overwrites ActiveSupport's ::encode and ::decode since they're so damn slow.
|
15
16
|
|
16
17
|
== Version 1.2.8
|
17
18
|
|
data/Rakefile
CHANGED
@@ -1,49 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
original
|
11
|
-
# Overwrites slow ActiveSupport ActiveSupport::JSON.encode by faster 1.9 stdlib JSON library
|
12
|
-
if RUBY_VERSION > '1.9'
|
13
|
-
[Array, Hash].each do |klass|
|
1
|
+
# Overwrites slow ActiveSupport ActiveSupport::JSON.encode by faster Yajl or JSON libraries
|
2
|
+
require 'active_support/core_ext/object/to_json'
|
3
|
+
begin
|
4
|
+
require 'yajl'
|
5
|
+
|
6
|
+
[Array, Hash, String].each do |klass|
|
14
7
|
klass.class_eval do
|
15
|
-
def to_json(
|
16
|
-
|
8
|
+
def to_json(*)
|
9
|
+
Yajl::Encoder.encode self
|
17
10
|
end
|
18
11
|
end
|
19
12
|
end
|
20
13
|
|
21
|
-
class
|
22
|
-
# nothing lost here since javascript engines (at least Webkit) doesn't order objects
|
23
|
-
def to_json(options=nil)
|
24
|
-
JSON.unparse({}.merge!(self), options)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class String
|
14
|
+
class String
|
29
15
|
# the opposite of #to_json
|
30
|
-
def from_json
|
31
|
-
|
16
|
+
def from_json(options={}) # :symbolize_keys
|
17
|
+
Yajl::Parser.parse self, options
|
32
18
|
end
|
33
|
-
end
|
34
|
-
|
35
|
-
else
|
36
|
-
|
37
|
-
def from_json
|
38
|
-
ActiveSupport::JSON.decode self
|
39
19
|
end
|
40
20
|
|
41
|
-
|
21
|
+
rescue LoadError
|
22
|
+
if defined? JSON
|
23
|
+
|
24
|
+
[Array, Hash].each do |klass|
|
25
|
+
klass.class_eval do
|
26
|
+
def to_json(options=nil)
|
27
|
+
JSON.unparse self, options
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# This is only case where JSON.unparse does not work (and for only few versions of json stdlib)
|
33
|
+
begin
|
34
|
+
JSON.unparse ActiveSupport::OrderedHash
|
35
|
+
rescue
|
36
|
+
class ActiveSupport::OrderedHash
|
37
|
+
# nothing lost here since javascript engines (at least Webkit) doesn't order objects
|
38
|
+
def to_json(options=nil)
|
39
|
+
JSON.unparse({}.merge!(self))#, options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class String
|
45
|
+
# the opposite of #to_json
|
46
|
+
def from_json
|
47
|
+
JSON.parse self
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
else
|
52
|
+
|
53
|
+
class String
|
54
|
+
# the opposite of #to_json
|
55
|
+
def from_json
|
56
|
+
ActiveSupport::JSON.decode self
|
57
|
+
end
|
58
|
+
end
|
42
59
|
|
43
|
-
|
60
|
+
end
|
61
|
+
end
|
44
62
|
|
63
|
+
class Object
|
64
|
+
# handy when data may not be encodable (active_record objects, recursive structures, etc)
|
45
65
|
def to_json_safe(options=nil)
|
46
66
|
timeout(10) {to_json(options)}
|
47
|
-
end
|
48
|
-
|
67
|
+
end
|
49
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmtools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 11
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
9
|
- 10
|
10
|
-
|
11
|
-
version: 1.2.10b
|
10
|
+
version: 1.2.10
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Sergey Baev
|
@@ -195,14 +194,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
195
|
none: false
|
197
196
|
requirements:
|
198
|
-
- - "
|
197
|
+
- - ">="
|
199
198
|
- !ruby/object:Gem::Version
|
200
|
-
hash:
|
199
|
+
hash: 3
|
201
200
|
segments:
|
202
|
-
-
|
203
|
-
|
204
|
-
- 1
|
205
|
-
version: 1.3.1
|
201
|
+
- 0
|
202
|
+
version: "0"
|
206
203
|
requirements: []
|
207
204
|
|
208
205
|
rubyforge_project: rmtools
|