rmtools 1.2.10b → 1.2.10

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.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
@@ -2,7 +2,7 @@ require 'rake'
2
2
  require 'lib/rmtools/install'
3
3
  compile_manifest
4
4
 
5
- RMTOOLS_VERSION = '1.2.10b'
5
+ RMTOOLS_VERSION = '1.2.10'
6
6
  begin
7
7
  require 'hoe'
8
8
  config = Hoe.spec 'rmtools' do
@@ -1,49 +1,68 @@
1
- <<-original
2
- [Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].each do |klass|
3
- klass.class_eval do
4
- # Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
5
- def to_json(options = nil)
6
- ActiveSupport::JSON.encode(self, options)
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(options=nil)
16
- JSON.unparse(self, options)
8
+ def to_json(*)
9
+ Yajl::Encoder.encode self
17
10
  end
18
11
  end
19
12
  end
20
13
 
21
- class ActiveSupport::OrderedHash
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
- JSON.parse self
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
- end
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
- class Object
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: 3
5
- prerelease: 6
4
+ hash: 11
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
9
  - 10
10
- - b
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: 25
199
+ hash: 3
201
200
  segments:
202
- - 1
203
- - 3
204
- - 1
205
- version: 1.3.1
201
+ - 0
202
+ version: "0"
206
203
  requirements: []
207
204
 
208
205
  rubyforge_project: rmtools