pump 0.6.6 → 0.7.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +3 -3
- data/CHANGES.md +10 -2
- data/Guardfile +5 -5
- data/benchmarks/Gemfile +9 -0
- data/benchmarks/Gemfile.lock +59 -0
- data/benchmarks/encode.rb +34 -3
- data/gemfiles/activesupport-4 +4 -3
- data/gemfiles/activesupport-5 +8 -0
- data/lib/pump/json.rb +5 -3
- data/lib/pump/version.rb +1 -1
- data/lib/pump/xml.rb +2 -2
- data/pump.gemspec +4 -3
- data/spec/pump/array_spec.rb +13 -13
- data/spec/pump/collection_spec.rb +13 -13
- data/spec/pump/dsl_spec.rb +2 -2
- data/spec/pump/encoder_spec.rb +10 -10
- data/spec/pump/json_spec.rb +40 -40
- data/spec/pump/object_spec.rb +23 -23
- data/spec/pump/xml/tag_array_spec.rb +2 -2
- data/spec/pump/xml/tag_spec.rb +2 -2
- data/spec/pump/xml/value_spec.rb +3 -3
- data/spec/pump/xml_spec.rb +48 -48
- data/spec/spec_helper.rb +6 -1
- metadata +39 -23
- data/gemfiles/activesupport-3-2 +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 180ae744ddb9c6df1c7d7bd415f75dd5b808de18
|
4
|
+
data.tar.gz: 8b3b23f23c25dce465b72bc5eb1c84ec740a9f39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a5e87c4721f61adf2b7fcf606dcff23f02daaa3d8e4c487b761989e6eff4978b429ce2e9451459a9cc98a9145d195e7b820b1d3eb6877f5f1650ec0e152de1d
|
7
|
+
data.tar.gz: d6093a04b4eade920916d7a16b1037e68c56704ac53ee53aed2a9fbe881499fe2e28214abb47b6f63009ea679e82f221fcd7b597842329081a1c18d111d02e1a
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](http://github.com/yolk/pump/compare/v0.
|
3
|
+
[full changelog](http://github.com/yolk/pump/compare/v0.7.0...master)
|
4
|
+
|
5
|
+
### 0.7.0 / 2017-06-26
|
6
|
+
|
7
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.6.6...v0.7.0)
|
8
|
+
|
9
|
+
* Fixed Fixnum warning in Ruby 2.4.1
|
10
|
+
* Test against ruby 2.3 and 2.4
|
11
|
+
* Updated to OJ 3.2
|
4
12
|
|
5
13
|
### 0.6.6 / 2014-07-03
|
6
14
|
|
@@ -47,4 +55,4 @@
|
|
47
55
|
[full changelog](http://github.com/yolk/valvat/compare/v0.5.1...v0.6.0)
|
48
56
|
|
49
57
|
* Added JSON serialization
|
50
|
-
* Added simple inheritance for encoders
|
58
|
+
* Added simple inheritance for encoders
|
data/Guardfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
guard
|
2
|
-
watch(
|
3
|
-
watch(
|
4
|
-
watch(
|
5
|
-
end
|
1
|
+
guard :rspec, cmd: "bundle exec rspec --color" do
|
2
|
+
watch(/^spec\/(.*)_spec.rb/)
|
3
|
+
watch(/^lib\/(.*)\.rb/) { |m| "spec/#{m[1]}_spec.rb" }
|
4
|
+
watch(/^spec\/spec_helper.rb/) { "spec" }
|
5
|
+
end
|
data/benchmarks/Gemfile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/ahacking/to_json.git
|
3
|
+
revision: 6fe8a17f9652da0d29c2ef8637630f7c34977e00
|
4
|
+
specs:
|
5
|
+
to_json (0.0.4)
|
6
|
+
oj (>= 2.9.4)
|
7
|
+
|
8
|
+
PATH
|
9
|
+
remote: ..
|
10
|
+
specs:
|
11
|
+
pump (0.6.6)
|
12
|
+
activesupport (>= 4.0)
|
13
|
+
oj (>= 3.0)
|
14
|
+
|
15
|
+
GEM
|
16
|
+
remote: https://rubygems.org/
|
17
|
+
specs:
|
18
|
+
activemodel (5.1.2)
|
19
|
+
activesupport (= 5.1.2)
|
20
|
+
activemodel-serializers-xml (1.0.1)
|
21
|
+
activemodel (> 5.x)
|
22
|
+
activerecord (> 5.x)
|
23
|
+
activesupport (> 5.x)
|
24
|
+
builder (~> 3.1)
|
25
|
+
activerecord (5.1.2)
|
26
|
+
activemodel (= 5.1.2)
|
27
|
+
activesupport (= 5.1.2)
|
28
|
+
arel (~> 8.0)
|
29
|
+
activesupport (5.1.2)
|
30
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
31
|
+
i18n (~> 0.7)
|
32
|
+
minitest (~> 5.1)
|
33
|
+
tzinfo (~> 1.1)
|
34
|
+
arel (8.0.0)
|
35
|
+
builder (3.2.3)
|
36
|
+
concurrent-ruby (1.0.5)
|
37
|
+
i18n (0.8.4)
|
38
|
+
minitest (5.10.2)
|
39
|
+
oj (3.2.0)
|
40
|
+
ox (2.5.0)
|
41
|
+
thread_safe (0.3.6)
|
42
|
+
tzinfo (1.2.3)
|
43
|
+
thread_safe (~> 0.1)
|
44
|
+
yajl-ruby (1.3.0)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
activemodel
|
51
|
+
activemodel-serializers-xml
|
52
|
+
oj
|
53
|
+
ox
|
54
|
+
pump!
|
55
|
+
to_json!
|
56
|
+
yajl-ruby
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
1.15.1
|
data/benchmarks/encode.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
#!/usr/bin/env ruby
|
3
2
|
require 'rubygems'
|
4
|
-
require '
|
3
|
+
require 'bundler/setup'
|
5
4
|
|
5
|
+
require 'benchmark'
|
6
|
+
require 'to_json'
|
6
7
|
require 'pump'
|
7
8
|
require 'ox'
|
8
9
|
require 'oj'
|
9
10
|
require 'yajl'
|
10
11
|
require 'active_model'
|
12
|
+
require 'activemodel-serializers-xml'
|
11
13
|
|
12
14
|
class Person < Struct.new(:name, :age, :created_at)
|
13
15
|
include ActiveModel::Serializers::Xml if defined?(ActiveModel)
|
@@ -24,6 +26,29 @@ pump_json = Pump::Json.new('person', [
|
|
24
26
|
{:name => :name}
|
25
27
|
])
|
26
28
|
|
29
|
+
module ToJsonBench
|
30
|
+
|
31
|
+
class PeopleSerializer
|
32
|
+
include ::ToJson::Serialize
|
33
|
+
|
34
|
+
def put_person(person)
|
35
|
+
put :name, person.name
|
36
|
+
put :age, person.age
|
37
|
+
put :"created-at", person.created_at.xmlschema
|
38
|
+
end
|
39
|
+
|
40
|
+
def put_people(people)
|
41
|
+
array people do |person|
|
42
|
+
put_person person
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def serialize(collection)
|
47
|
+
put_people collection
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
27
52
|
# Not optimized pump
|
28
53
|
pump = Pump::Xml.new('person', [
|
29
54
|
{:age => :age, :attributes => {:type => 'integer'}},
|
@@ -92,6 +117,12 @@ Benchmark.bmbm { |x|
|
|
92
117
|
}
|
93
118
|
}
|
94
119
|
|
120
|
+
x.report("ToJson") {
|
121
|
+
times.times {
|
122
|
+
ToJsonBench::PeopleSerializer.json!(array)
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
95
126
|
x.report("Pump::Xml#encode") {
|
96
127
|
times.times {
|
97
128
|
pump.encode(array)
|
data/gemfiles/activesupport-4
CHANGED
data/lib/pump/json.rb
CHANGED
@@ -8,9 +8,11 @@ module Pump
|
|
8
8
|
private
|
9
9
|
|
10
10
|
OJ_OPTIONS = {
|
11
|
-
:mode => :
|
11
|
+
:mode => :custom,
|
12
|
+
:second_precision => 0,
|
12
13
|
:time_format => :xmlschema,
|
13
|
-
:
|
14
|
+
:create_additions => false,
|
15
|
+
:use_as_json => true
|
14
16
|
}
|
15
17
|
|
16
18
|
def compile_string
|
@@ -145,4 +147,4 @@ module Pump
|
|
145
147
|
name.to_s.underscore
|
146
148
|
end
|
147
149
|
end
|
148
|
-
end
|
150
|
+
end
|
data/lib/pump/version.rb
CHANGED
data/lib/pump/xml.rb
CHANGED
@@ -72,7 +72,7 @@ module Pump
|
|
72
72
|
VALID_XML_CHARS = Regexp.new('\A['+
|
73
73
|
VALID_CHAR.map { |item|
|
74
74
|
case item
|
75
|
-
when
|
75
|
+
when 0.class
|
76
76
|
[item].pack('U').force_encoding('utf-8')
|
77
77
|
when Range
|
78
78
|
[item.first, '-'.ord, item.last].pack('UUU').force_encoding('utf-8')
|
@@ -96,4 +96,4 @@ end
|
|
96
96
|
|
97
97
|
require "pump/xml/tag"
|
98
98
|
require "pump/xml/value"
|
99
|
-
require "pump/xml/tag_array"
|
99
|
+
require "pump/xml/tag_array"
|
data/pump.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_dependency "activesupport", ">=
|
22
|
-
gem.add_dependency "oj", ">=
|
23
|
-
gem.add_development_dependency "rspec", ">= 2
|
21
|
+
gem.add_dependency "activesupport", ">= 4.0"
|
22
|
+
gem.add_dependency "oj", ">= 3.0"
|
23
|
+
gem.add_development_dependency "rspec", ">= 3.2"
|
24
|
+
gem.add_development_dependency "rspec-its"
|
24
25
|
end
|
data/spec/pump/array_spec.rb
CHANGED
@@ -40,22 +40,22 @@ end
|
|
40
40
|
|
41
41
|
describe Pump::Array do
|
42
42
|
it "should extend ::Array by default with pump_to_xml" do
|
43
|
-
[].respond_to?(:pump_to_xml).
|
43
|
+
expect([].respond_to?(:pump_to_xml)).to eql(true)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should extend ::Array by default with pump_to_json" do
|
47
|
-
[].respond_to?(:pump_to_json).
|
47
|
+
expect([].respond_to?(:pump_to_json)).to eql(true)
|
48
48
|
end
|
49
49
|
|
50
50
|
context "with objects without include" do
|
51
51
|
subject{ [ArrayObjectWithoutInclude.new] }
|
52
52
|
|
53
53
|
it "should return default to_xml" do
|
54
|
-
subject.pump_to_xml.
|
54
|
+
expect(subject.pump_to_xml).to eql(subject.to_xml)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should return default to_json" do
|
58
|
-
subject.pump_to_json.
|
58
|
+
expect(subject.pump_to_json).to eql(subject.to_json)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -63,11 +63,11 @@ describe Pump::Array do
|
|
63
63
|
subject{ [ArrayObjectWithInclude.new] }
|
64
64
|
|
65
65
|
it "should return default to_xml" do
|
66
|
-
subject.pump_to_xml.
|
66
|
+
expect(subject.pump_to_xml).to eql(subject.to_xml)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should return default to_json" do
|
70
|
-
subject.pump_to_json.
|
70
|
+
expect(subject.pump_to_json).to eql(subject.to_json)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -75,31 +75,31 @@ describe Pump::Array do
|
|
75
75
|
subject{ [ArrayObject.new] }
|
76
76
|
|
77
77
|
it "should encode with default encoder" do
|
78
|
-
subject.pump_to_xml.
|
78
|
+
expect(subject.pump_to_xml).to eql("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<array-objects type=\"array\">\n <array-object>\n <name>Tintin</name>\n </array-object>\n</array-objects>\n")
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should encode with specified encoder" do
|
82
|
-
subject.pump_to_xml(:set => :with_age).
|
82
|
+
expect(subject.pump_to_xml(:set => :with_age)).to eql("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<array-objects type=\"array\">\n <array-object>\n <name>Tintin</name>\n <age type=\"integer\">27</age>\n </array-object>\n</array-objects>\n")
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should encode with default encoder on unknown set" do
|
86
|
-
subject.pump_to_xml(:set => :bla).
|
86
|
+
expect(subject.pump_to_xml(:set => :bla)).to eql("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<array-objects type=\"array\">\n <array-object>\n <name>Tintin</name>\n </array-object>\n</array-objects>\n")
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should encode json with default encoder" do
|
90
|
-
subject.pump_to_json.
|
90
|
+
expect(subject.pump_to_json).to eql("[{\"array_object\":{\"name\":\"Tintin\"}}]")
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should encode json with specified encoder" do
|
94
|
-
subject.pump_to_json(:set => :with_age).
|
94
|
+
expect(subject.pump_to_json(:set => :with_age)).to eql("[{\"array_object\":{\"name\":\"Tintin\",\"age\":27}}]")
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should encode json with default encoder on unknown set" do
|
98
|
-
subject.pump_to_json(:set => :bla).
|
98
|
+
expect(subject.pump_to_json(:set => :bla)).to eql("[{\"array_object\":{\"name\":\"Tintin\"}}]")
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should pass down options to encoder" do
|
102
|
-
subject.pump_to_json(:exclude_root_in_json => true).
|
102
|
+
expect(subject.pump_to_json(:exclude_root_in_json => true)).to eql("[{\"name\":\"Tintin\"}]")
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -6,7 +6,7 @@ describe Pump::Collection do
|
|
6
6
|
describe ".new" do
|
7
7
|
it "should not accept any arguments" do
|
8
8
|
subject
|
9
|
-
|
9
|
+
expect{ Pump::Collection.new("") }.to raise_error(ArgumentError)
|
10
10
|
end
|
11
11
|
|
12
12
|
its(:size) { should eql(0) }
|
@@ -15,43 +15,43 @@ describe Pump::Collection do
|
|
15
15
|
describe "#add" do
|
16
16
|
it "should add entry" do
|
17
17
|
subject.add(:set_name, :xml, :value)
|
18
|
-
subject.size.
|
18
|
+
expect(subject.size).to eql(1)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should allow different formats" do
|
22
22
|
subject.add(:set_name, :json, :value)
|
23
|
-
subject.size.
|
23
|
+
expect(subject.size).to eql(1)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should default to :default set" do
|
27
27
|
subject.add(nil, :xml, :value)
|
28
|
-
subject.get(:default, :xml).
|
28
|
+
expect(subject.get(:default, :xml)).to eql(:value)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#get" do
|
33
33
|
it "should return nil on unknown entry" do
|
34
|
-
subject.get(:set_name, :xml).
|
35
|
-
subject.get(:default, :xml).
|
36
|
-
subject.get(nil, :xml).
|
37
|
-
subject.get(:default, :json).
|
34
|
+
expect(subject.get(:set_name, :xml)).to eql(nil)
|
35
|
+
expect(subject.get(:default, :xml)).to eql(nil)
|
36
|
+
expect(subject.get(nil, :xml)).to eql(nil)
|
37
|
+
expect(subject.get(:default, :json)).to eql(nil)
|
38
38
|
end
|
39
39
|
|
40
40
|
context "when entries are added" do
|
41
41
|
before{ subject.add(:set_name, :xml, :value); subject.add(:default, :xml, :value2) }
|
42
42
|
|
43
43
|
it "should return given value" do
|
44
|
-
subject.get(:set_name, :xml).
|
45
|
-
subject.get(:default, :xml).
|
44
|
+
expect(subject.get(:set_name, :xml)).to eql(:value)
|
45
|
+
expect(subject.get(:default, :xml)).to eql(:value2)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should return nil with wrong format" do
|
49
|
-
subject.get(:set_name, :json).
|
50
|
-
subject.get(:default, :json).
|
49
|
+
expect(subject.get(:set_name, :json)).to eql(nil)
|
50
|
+
expect(subject.get(:default, :json)).to eql(nil)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should default to :default on unknwon set" do
|
54
|
-
subject.get(:unknown, :xml).
|
54
|
+
expect(subject.get(:unknown, :xml)).to eql(:value2)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
data/spec/pump/dsl_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe Pump::Dsl do
|
|
5
5
|
|
6
6
|
describe ".new" do
|
7
7
|
it "requires one block" do
|
8
|
-
|
9
|
-
|
8
|
+
expect{ Pump::Dsl.new }.to raise_error(ArgumentError)
|
9
|
+
expect{ subject }.not_to raise_error
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
data/spec/pump/encoder_spec.rb
CHANGED
@@ -3,10 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe Pump::Encoder do
|
4
4
|
describe ".new" do
|
5
5
|
it "requires two parameters or one and a block" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
expect{ Pump::Encoder.new }.to raise_error(ArgumentError)
|
7
|
+
expect{ Pump::Encoder.new('record') }.to raise_error(ArgumentError)
|
8
|
+
expect{ Pump::Encoder.new('record', []) }.not_to raise_error
|
9
|
+
expect{ Pump::Encoder.new('record') {} }.not_to raise_error
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "with block given" do
|
@@ -30,7 +30,7 @@ describe Pump::Encoder do
|
|
30
30
|
|
31
31
|
it "leaves base config untouched" do
|
32
32
|
subject
|
33
|
-
base.encoder_config.
|
33
|
+
expect(base.encoder_config).to eql([{:name => :name}, {:role => :role}])
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -40,7 +40,7 @@ describe Pump::Encoder do
|
|
40
40
|
|
41
41
|
it "leaves base config untouched" do
|
42
42
|
subject
|
43
|
-
base.encoder_config.
|
43
|
+
expect(base.encoder_config).to eql([{:name => :name}, {:role => :role}])
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -50,7 +50,7 @@ describe Pump::Encoder do
|
|
50
50
|
|
51
51
|
it "leaves base config untouched" do
|
52
52
|
subject
|
53
|
-
base.encoder_config.
|
53
|
+
expect(base.encoder_config).to eql([{:name => :name}, {:role => :role}])
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -65,7 +65,7 @@ describe Pump::Encoder do
|
|
65
65
|
|
66
66
|
it "leaves base config untouched" do
|
67
67
|
subject
|
68
|
-
base.encoder_config.
|
68
|
+
expect(base.encoder_config).to eql([{:name => :name}, {:role => :role}])
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -76,7 +76,7 @@ describe Pump::Encoder do
|
|
76
76
|
|
77
77
|
it "leaves base options untouched" do
|
78
78
|
subject
|
79
|
-
base.encoder_options.
|
79
|
+
expect(base.encoder_options).to eql({:option => true})
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -88,7 +88,7 @@ describe Pump::Encoder do
|
|
88
88
|
|
89
89
|
it "leaves base options untouched" do
|
90
90
|
subject
|
91
|
-
base.encoder_options.
|
91
|
+
expect(base.encoder_options).to eql({:option => true})
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|