pump 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -1
- data/lib/pump/encoder.rb +1 -0
- data/lib/pump/json.rb +23 -12
- data/lib/pump/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c60ca511d26b937009e1b16e1473b4e664509ab9
|
4
|
+
data.tar.gz: 0f6c9cf439f290237b710c56ed25d87b79ccca5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf21d8aa68ff75a6bb584390bdc16880a48c600057834dcb2aac8457c76268a20e294c8900056854a3019f13065f2eccd8e19ac5e70cac17d4f4b3700914a941
|
7
|
+
data.tar.gz: d1441b8fb1321f5452a25d98568ac35bc9e0a5d0b72866eae2bc795b2bdccb3570def280d700e84c203d5d72f05c081dd28a519014f4475c8d093e2b956b6f84
|
data/CHANGES.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](http://github.com/yolk/pump/compare/v0.6.
|
3
|
+
[full changelog](http://github.com/yolk/pump/compare/v0.6.2...master)
|
4
|
+
|
5
|
+
### 0.6.2 / 2013-07-26
|
6
|
+
|
7
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.6.1...v0.6.2)
|
8
|
+
|
9
|
+
* Pump::Encoder now forces loading of ActiveRecord::Relation to detect array
|
10
|
+
* Format times correctly with OJ options alone (does not rely on activesupports to_json)
|
4
11
|
|
5
12
|
### 0.6.1 / 2013-07-25
|
6
13
|
|
data/lib/pump/encoder.rb
CHANGED
@@ -52,6 +52,7 @@ module Pump
|
|
52
52
|
#
|
53
53
|
# @return [String]
|
54
54
|
def encode(object, options={})
|
55
|
+
object = object.to_a if defined?(ActiveRecord::Relation) && object.is_a?(ActiveRecord::Relation)
|
55
56
|
object.is_a?(Array) ? encode_array(object, options) : encode_single(object, options)
|
56
57
|
end
|
57
58
|
|
data/lib/pump/json.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "pump/encoder"
|
2
|
-
|
2
|
+
|
3
3
|
require "oj"
|
4
4
|
|
5
5
|
module Pump
|
@@ -7,36 +7,47 @@ module Pump
|
|
7
7
|
|
8
8
|
private
|
9
9
|
|
10
|
+
OJ_OPTIONS = {
|
11
|
+
:mode => :compat,
|
12
|
+
:time_format => :xmlschema,
|
13
|
+
:second_precision => 0
|
14
|
+
}
|
15
|
+
|
10
16
|
def compile_string
|
17
|
+
main = build_main
|
11
18
|
<<-EOV
|
12
19
|
def encode_single(object, options)
|
13
|
-
|
14
|
-
#{build_string(encoder_config)}
|
20
|
+
#{main}
|
15
21
|
unless options[:exclude_root_in_json]
|
16
22
|
json = { :'#{format_name(root_name)}' => json }
|
17
23
|
end
|
18
|
-
Oj.dump(json,
|
24
|
+
Oj.dump(json, OJ_OPTIONS)
|
19
25
|
end
|
20
26
|
|
21
27
|
def encode_array(objects, options)
|
22
28
|
Oj.dump(if options[:exclude_root_in_json]
|
23
29
|
objects.map do |object|
|
24
|
-
|
25
|
-
#{build_string(encoder_config)}
|
30
|
+
#{main}
|
26
31
|
json
|
27
32
|
end
|
28
33
|
else
|
29
34
|
objects.map do |object|
|
30
|
-
|
31
|
-
#{build_string(encoder_config)}
|
35
|
+
#{main}
|
32
36
|
{ :'#{format_name(root_name)}' => json }
|
33
37
|
end
|
34
|
-
end,
|
38
|
+
end, OJ_OPTIONS)
|
35
39
|
end
|
36
40
|
EOV
|
37
41
|
end
|
38
42
|
|
39
|
-
def
|
43
|
+
def build_main
|
44
|
+
<<-EOV
|
45
|
+
json = {}
|
46
|
+
#{build_part(encoder_config)}
|
47
|
+
EOV
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_part(config, variable='json')
|
40
51
|
config.inject("") do |str, config|
|
41
52
|
build_key_value_pair(str, config, variable)
|
42
53
|
str
|
@@ -57,7 +68,7 @@ module Pump
|
|
57
68
|
def build_hash(str, name, method_name, config, variable)
|
58
69
|
str << "#{build_condition(config)}\n"
|
59
70
|
str << "#{variable}[:'#{format_name(name)}'] = {}\n"
|
60
|
-
str <<
|
71
|
+
str << build_part(method_name, "#{variable}[:'#{format_name(name)}']")
|
61
72
|
str << "end\n" if build_condition(config)
|
62
73
|
end
|
63
74
|
|
@@ -67,7 +78,7 @@ module Pump
|
|
67
78
|
unless config.has_key?(:static_value)
|
68
79
|
str << "object.#{method_name}.each do |object| "
|
69
80
|
str << "#{variable}[:'#{format_name(name)}'] << {}\n"
|
70
|
-
str <<
|
81
|
+
str << build_part(config[:array], "#{variable}[:'#{format_name(name)}'][-1]")
|
71
82
|
str << "end\n"
|
72
83
|
end
|
73
84
|
str << "end\n" if build_condition(config)
|
data/lib/pump/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Munz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|