ixtlan-babel 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -1
- data/lib/ixtlan/babel/abstract_filter.rb +3 -3
- data/lib/ixtlan/babel/dm_validation_errors_serializer.rb +1 -1
- data/lib/ixtlan/babel/factory.rb +3 -2
- data/lib/ixtlan/babel/filter_config.rb +8 -6
- data/lib/ixtlan/babel/hash_filter.rb +6 -4
- data/lib/ixtlan/babel/model_filter.rb +11 -5
- data/lib/ixtlan/babel/params_filter.rb +36 -7
- data/lib/ixtlan/babel/serializer.rb +7 -6
- data/spec/hash_filter_spec.rb +45 -19
- data/spec/model_filter_spec.rb +53 -137
- data/spec/model_filter_with_methods_spec.rb +68 -101
- data/spec/params_filter_spec.rb +42 -36
- metadata +27 -46
- data/lib/ixtlan/babel/deserializer.rb +0 -88
- data/lib/ixtlan/babel/hash_filter.rb- +0 -170
- data/lib/ixtlan/babel/no_timestamp_serializer.rb +0 -40
@@ -11,7 +11,7 @@ class Area2
|
|
11
11
|
include Virtus
|
12
12
|
|
13
13
|
attribute :code, String
|
14
|
-
attribute :iso, String
|
14
|
+
attribute :iso, String
|
15
15
|
end
|
16
16
|
class PhoneNumber2
|
17
17
|
include Virtus
|
@@ -30,12 +30,12 @@ class Person2
|
|
30
30
|
attr_accessor :phone_numbers, :age, :children_names
|
31
31
|
|
32
32
|
def phone_numbers
|
33
|
-
@phone_numbers ||= [PhoneNumber2.new(
|
34
|
-
:prefix => 12,
|
33
|
+
@phone_numbers ||= [PhoneNumber2.new(
|
34
|
+
:prefix => 12,
|
35
35
|
:number => '123',
|
36
36
|
:area => Area2.new( :code => '001', :iso => 'us' ) )]
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def age
|
40
40
|
@age ||= 123
|
41
41
|
end
|
@@ -53,132 +53,99 @@ describe Ixtlan::Babel::ModelFilter.to_s + ':with_methods' do
|
|
53
53
|
let( :person ) do
|
54
54
|
Person2.new( :id => 987,
|
55
55
|
:name => 'me and the corner',
|
56
|
-
:address => Address2.new( :street => 'Foo 12',
|
56
|
+
:address => Address2.new( :street => 'Foo 12',
|
57
|
+
:zipcode => '12345' ) )
|
57
58
|
end
|
58
59
|
|
59
60
|
let(:serializer) { Ixtlan::Babel::Serializer.new( person ) }
|
60
|
-
let(:deserializer) { Ixtlan::Babel::Deserializer.new( Person2 ) }
|
61
61
|
|
62
62
|
it 'should serialize and deserialize with methods' do
|
63
|
-
json = serializer.to_json(:include =>
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
63
|
+
json = serializer.to_json( :include =>
|
64
|
+
[:age, :children_names, :children_ages])
|
65
|
+
result = MultiJson.load(json)
|
66
|
+
result.must_equal Hash[ "id"=>"987",
|
67
|
+
"name"=>"me and the corner",
|
68
|
+
"age"=>123,
|
69
|
+
"children_names"=> [ "anna",
|
70
|
+
"jack",
|
71
|
+
"rama",
|
72
|
+
"mia" ],
|
73
|
+
"children_ages"=>[ 12, 3, 6, 9 ] ]
|
71
74
|
end
|
72
75
|
|
73
76
|
it 'should serialize and deserialize without root' do
|
74
77
|
json = serializer.to_json
|
75
|
-
result =
|
76
|
-
|
77
|
-
attributes.must_equal Hash[:id => person['id'], :name => person['name']]
|
78
|
+
result = MultiJson.load(json)
|
79
|
+
result.must_equal Hash[ "id"=>"987", "name"=>"me and the corner" ]
|
78
80
|
end
|
79
81
|
|
80
82
|
it 'should serialize and deserialize with root' do
|
81
83
|
json = serializer.to_json :root => 'my'
|
82
|
-
result =
|
83
|
-
|
84
|
-
|
85
|
-
end
|
84
|
+
result = MultiJson.load(json)[ 'my' ]
|
85
|
+
result.must_equal Hash[ "id"=>"987", "name"=>"me and the corner" ]
|
86
|
+
end
|
86
87
|
|
87
88
|
it 'should serialize and deserialize a hash with include list' do
|
88
|
-
json = serializer.to_json(:include => ['address', 'phone_numbers'])
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
result.phone_numbers[0].prefix.must_equal person.phone_numbers[0].prefix
|
98
|
-
result.phone_numbers[0].number.must_equal person.phone_numbers[0].number
|
99
|
-
result.name.must_equal person.name
|
100
|
-
result.id.must_equal person.id
|
89
|
+
json = serializer.to_json(:include => ['address', 'phone_numbers'])
|
90
|
+
result = MultiJson.load(json)
|
91
|
+
result.must_equal Hash[ "id"=>"987", "name"=>"me and the corner" ,
|
92
|
+
"address"=> {
|
93
|
+
"street"=>"Foo 12",
|
94
|
+
"zipcode"=>"12345"
|
95
|
+
},
|
96
|
+
"phone_numbers"=> [ { "prefix"=>12,
|
97
|
+
"number"=>"123" } ] ]
|
101
98
|
end
|
102
99
|
|
103
100
|
it 'shouldserialize and deserialize with except' do
|
104
|
-
json = serializer.to_json(:except => ['id'])
|
105
|
-
result =
|
106
|
-
result.
|
107
|
-
result = deserializer.from_json(json)
|
108
|
-
result.attributes.must_equal Hash[:name => person['name'], :address=>nil, :id => nil]
|
101
|
+
json = serializer.to_json(:except => ['id'])
|
102
|
+
result = MultiJson.load(json)
|
103
|
+
result.must_equal Hash[ "name"=>"me and the corner" ]
|
109
104
|
end
|
110
105
|
|
111
106
|
it 'should serialize and deserialize with only' do
|
112
|
-
json = serializer.to_json(:only => ['name'])
|
113
|
-
result =
|
114
|
-
result.
|
115
|
-
result = deserializer.from_json(json)
|
116
|
-
result.attributes.must_equal Hash[:name => person['name'], :address=>nil, :id => nil]
|
107
|
+
json = serializer.to_json(:only => ['name'])
|
108
|
+
result = MultiJson.load(json)
|
109
|
+
result.must_equal Hash[ "name"=>"me and the corner" ]
|
117
110
|
end
|
118
111
|
|
119
112
|
it 'should serialize and deserialize with nested only' do
|
120
|
-
json = serializer.to_json(:include => { 'address' => {
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
result.name.must_equal person.name
|
129
|
-
result.id.must_equal person.id
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should serialize and deserialize with nested only (array includes)' do
|
133
|
-
json = serializer.to_json(:include => { 'address' => {:only => ['street']}})
|
134
|
-
result = deserializer.from_json(json, :include => ['address'])
|
135
|
-
|
136
|
-
json['phone_numbers'].must_be_nil
|
137
|
-
json['address']['zipcode'].must_be_nil
|
138
|
-
|
139
|
-
result.address.zipcode.must_be_nil
|
140
|
-
|
141
|
-
result.name.must_equal person.name
|
142
|
-
result.id.must_equal person.id
|
113
|
+
json = serializer.to_json(:include => { 'address' => {
|
114
|
+
:only => ['street'] } } )
|
115
|
+
result = MultiJson.load(json)
|
116
|
+
result.must_equal Hash[ "id"=>"987", "name"=>"me and the corner" ,
|
117
|
+
"address"=> {
|
118
|
+
"street"=>"Foo 12"
|
119
|
+
} ]
|
143
120
|
end
|
144
121
|
|
145
122
|
it 'should serialize and deserialize with nested except' do
|
146
|
-
json = serializer.to_json(:include => {
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
result.name.must_equal person.name
|
155
|
-
result.id.must_equal person.id
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'should serialize and deserialize with nested except (array includes)' do
|
159
|
-
json = serializer.to_json(:include => { 'address' => {:except => ['zipcode']}})
|
160
|
-
result = deserializer.from_json(json, :include => ['address'])
|
161
|
-
|
162
|
-
json['phone_numbers'].must_be_nil
|
163
|
-
json['address']['zipcode'].must_be_nil
|
164
|
-
|
165
|
-
result.address.zipcode.must_be_nil
|
166
|
-
|
167
|
-
result.name.must_equal person.name
|
168
|
-
result.id.must_equal person.id
|
123
|
+
json = serializer.to_json(:include => {
|
124
|
+
'address' => {:except => ['zipcode'] } } )
|
125
|
+
result = MultiJson.load(json)
|
126
|
+
result.must_equal Hash[ "id"=>"987", "name"=>"me and the corner" ,
|
127
|
+
"address"=> {
|
128
|
+
"street"=>"Foo 12"
|
129
|
+
} ]
|
169
130
|
end
|
170
131
|
|
171
132
|
it 'should serialize and deserialize with nested include' do
|
172
|
-
json = serializer.to_json(:include => {
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
result
|
177
|
-
result.
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
133
|
+
json = serializer.to_json(:include => {
|
134
|
+
'address' => {},
|
135
|
+
'phone_numbers' => { :include => ['area'] }
|
136
|
+
} )
|
137
|
+
result = MultiJson.load(json)
|
138
|
+
result.must_equal Hash[ "id"=>"987", "name"=>"me and the corner" ,
|
139
|
+
"address"=> {
|
140
|
+
"street"=>"Foo 12",
|
141
|
+
"zipcode"=>"12345"
|
142
|
+
},
|
143
|
+
"phone_numbers"=> [ { "prefix"=>12,
|
144
|
+
"number"=>"123",
|
145
|
+
"area"=> {
|
146
|
+
"code"=>"001",
|
147
|
+
"iso"=>"us"
|
148
|
+
}
|
149
|
+
} ] ]
|
183
150
|
end
|
184
151
|
end
|
data/spec/params_filter_spec.rb
CHANGED
@@ -21,8 +21,8 @@ describe Ixtlan::Babel::ParamsFilter do
|
|
21
21
|
'id' => 987,
|
22
22
|
'name' => 'me and the corner',
|
23
23
|
'address' => { 'street' => 'Foo 12', 'zipcode' => '12345' },
|
24
|
-
'phone_numbers' => {
|
25
|
-
'prefix' => 12,
|
24
|
+
'phone_numbers' => {
|
25
|
+
'prefix' => 12,
|
26
26
|
'number' => '123',
|
27
27
|
'area' => { 'code' => '001', 'iso' => 'us'}
|
28
28
|
}
|
@@ -34,74 +34,80 @@ describe Ixtlan::Babel::ParamsFilter do
|
|
34
34
|
let(:deserializer) { Ixtlan::Babel::Deserializer.new(Hash) }
|
35
35
|
|
36
36
|
it 'should filter a hash' do
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
result = filter.filter_it( data )
|
38
|
+
result.params.must_equal Hash[ 'id' => data['id'], 'name' => data['name'] ]
|
39
|
+
result.size.must_equal 1
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should filter a hash with keep' do
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
result = filter.use( :keep => ['id'] ).filter_it( data )
|
44
|
+
result.params.must_equal Hash[ 'name' => data['name'] ]
|
45
|
+
result[ 'id' ].must_equal data['id']
|
46
|
+
result.size.must_equal 2
|
46
47
|
end
|
47
48
|
|
48
49
|
it 'should filter a hash with root' do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
50
|
+
result = filter.use( :root => 'my' ).filter_it( 'my' => data )
|
51
|
+
result.params.must_equal Hash[ 'id' => data['id'], 'name' => data['name'] ]
|
52
|
+
result.size.must_equal 1
|
53
|
+
end
|
53
54
|
|
54
55
|
it 'should filter a hash with include list' do
|
55
|
-
|
56
|
+
result = filter.use( :include => ['address',
|
57
|
+
'phone_numbers'] ).filter_it( data )
|
56
58
|
|
57
59
|
data['phone_numbers'].delete('area')
|
58
|
-
|
59
|
-
|
60
|
+
result.params.must_equal Hash[data]
|
61
|
+
result.size.must_equal 1
|
60
62
|
end
|
61
63
|
|
62
64
|
it 'should filter a hash with except' do
|
63
|
-
|
64
|
-
|
65
|
-
|
65
|
+
result = filter.use( :except => ['id'] ).filter_it( data )
|
66
|
+
result.params.must_equal Hash['name' => data['name']]
|
67
|
+
result.size.must_equal 1
|
66
68
|
end
|
67
69
|
|
68
70
|
it 'should filter a hash with except and keep' do
|
69
|
-
|
70
|
-
|
71
|
-
|
71
|
+
result = filter.use( :except => ['id'], :keep => ['id'] ).filter_it( data )
|
72
|
+
result.params.must_equal Hash['name' => data['name']]
|
73
|
+
result['id'].must_equal data['id']
|
72
74
|
end
|
73
75
|
|
74
76
|
it 'should filter a hash with only' do
|
75
|
-
|
76
|
-
|
77
|
-
|
77
|
+
result = filter.use( :only => ['name'] ).filter_it( data )
|
78
|
+
result.params.must_equal Hash['name' => data['name']]
|
79
|
+
result.size.must_equal 1
|
78
80
|
end
|
79
81
|
|
80
82
|
it 'should filter a hash with only and keep' do
|
81
|
-
|
82
|
-
|
83
|
-
|
83
|
+
result = filter.use( :only => ['name'], :keep => ['id'] ).filter_it( data )
|
84
|
+
result.params.must_equal Hash['name' => data['name']]
|
85
|
+
result[ 'id' ].must_equal data['id']
|
86
|
+
result.size.must_equal 2
|
84
87
|
end
|
85
88
|
|
86
89
|
it 'should filter a hash with nested only' do
|
87
|
-
|
90
|
+
result = filter.use( :include => { 'address' =>
|
91
|
+
{:only => ['street']}} ).filter_it( data )
|
88
92
|
data.delete('phone_numbers')
|
89
93
|
data['address'].delete('zipcode')
|
90
|
-
|
91
|
-
|
94
|
+
result.params.must_equal Hash[data]
|
95
|
+
result.size.must_equal 1
|
92
96
|
end
|
93
97
|
|
94
98
|
it 'should filter a hash with nested except' do
|
95
|
-
|
99
|
+
result = filter.use( :include => { 'address' =>
|
100
|
+
{:except => ['zipcode']}} ).filter_it( data )
|
96
101
|
data.delete('phone_numbers')
|
97
102
|
data['address'].delete('zipcode')
|
98
|
-
|
99
|
-
|
103
|
+
result.params.must_equal Hash[data]
|
104
|
+
result.size.must_equal 1
|
100
105
|
end
|
101
106
|
|
102
107
|
it 'should filter a hash with nested include' do
|
103
|
-
|
104
|
-
|
105
|
-
|
108
|
+
result = filter.use( :include => { 'address' => {}, 'phone_numbers' =>
|
109
|
+
{ :include => ['area']}} ).filter_it( data )
|
110
|
+
result.params.must_equal Hash[data]
|
111
|
+
result.size.must_equal 1
|
106
112
|
end
|
107
113
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ixtlan-babel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.3.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Christian Meier
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -17,29 +17,13 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 10.0
|
20
|
+
version: '10.0'
|
21
21
|
none: false
|
22
22
|
requirement: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 10.0
|
27
|
-
none: false
|
28
|
-
prerelease: false
|
29
|
-
type: :development
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: copyright-header
|
32
|
-
version_requirements: !ruby/object:Gem::Requirement
|
33
|
-
requirements:
|
34
|
-
- - "~>"
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 1.0.7
|
37
|
-
none: false
|
38
|
-
requirement: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - "~>"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 1.0.7
|
26
|
+
version: '10.0'
|
43
27
|
none: false
|
44
28
|
prerelease: false
|
45
29
|
type: :development
|
@@ -49,13 +33,13 @@ dependencies:
|
|
49
33
|
requirements:
|
50
34
|
- - "~>"
|
51
35
|
- !ruby/object:Gem::Version
|
52
|
-
version: '4.
|
36
|
+
version: '4.0'
|
53
37
|
none: false
|
54
38
|
requirement: !ruby/object:Gem::Requirement
|
55
39
|
requirements:
|
56
40
|
- - "~>"
|
57
41
|
- !ruby/object:Gem::Version
|
58
|
-
version: '4.
|
42
|
+
version: '4.0'
|
59
43
|
none: false
|
60
44
|
prerelease: false
|
61
45
|
type: :development
|
@@ -65,13 +49,13 @@ dependencies:
|
|
65
49
|
requirements:
|
66
50
|
- - "~>"
|
67
51
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.5
|
52
|
+
version: '0.5'
|
69
53
|
none: false
|
70
54
|
requirement: !ruby/object:Gem::Requirement
|
71
55
|
requirements:
|
72
56
|
- - "~>"
|
73
57
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.5
|
58
|
+
version: '0.5'
|
75
59
|
none: false
|
76
60
|
prerelease: false
|
77
61
|
type: :development
|
@@ -115,39 +99,36 @@ extensions: []
|
|
115
99
|
extra_rdoc_files: []
|
116
100
|
files:
|
117
101
|
- lib/ixtlan-babel.rb
|
118
|
-
- lib/ixtlan/babel/
|
102
|
+
- lib/ixtlan/babel/dm_validation_errors_serializer.rb~
|
103
|
+
- lib/ixtlan/babel/context.rb~
|
104
|
+
- lib/ixtlan/babel/filter_config.rb~
|
105
|
+
- lib/ixtlan/babel/context.rb
|
106
|
+
- lib/ixtlan/babel/hash_only_filter.rb~
|
119
107
|
- lib/ixtlan/babel/hash_filter.rb
|
108
|
+
- lib/ixtlan/babel/abstract_filter.rb~
|
120
109
|
- lib/ixtlan/babel/serializer.rb~
|
110
|
+
- lib/ixtlan/babel/serializer.rb
|
111
|
+
- lib/ixtlan/babel/factory.rb~
|
112
|
+
- lib/ixtlan/babel/config.rb~
|
121
113
|
- lib/ixtlan/babel/params_filter.rb
|
122
|
-
- lib/ixtlan/babel/abstract_filter.rb
|
123
|
-
- lib/ixtlan/babel/no_timestamp_serializer.rb
|
124
|
-
- lib/ixtlan/babel/filter_config.rb
|
125
|
-
- lib/ixtlan/babel/params_filter.rb~
|
126
|
-
- lib/ixtlan/babel/context.rb
|
127
114
|
- lib/ixtlan/babel/factory.rb
|
128
115
|
- lib/ixtlan/babel/model_filter.rb~
|
116
|
+
- lib/ixtlan/babel/model_filter.rb
|
117
|
+
- lib/ixtlan/babel/params_filter.rb~
|
118
|
+
- lib/ixtlan/babel/filter_config.rb
|
119
|
+
- lib/ixtlan/babel/abstract_filter.rb
|
129
120
|
- lib/ixtlan/babel/dm_validation_errors_serializer.rb
|
130
121
|
- lib/ixtlan/babel/hash_filter.rb~
|
131
|
-
- lib/ixtlan/babel/filter_config.rb~
|
132
|
-
- lib/ixtlan/babel/hash_only_filter.rb~
|
133
|
-
- lib/ixtlan/babel/factory.rb~
|
134
|
-
- lib/ixtlan/babel/dm_validation_errors_serializer.rb~
|
135
|
-
- lib/ixtlan/babel/context.rb~
|
136
|
-
- lib/ixtlan/babel/model_filter.rb
|
137
|
-
- lib/ixtlan/babel/hash_filter.rb-
|
138
|
-
- lib/ixtlan/babel/abstract_filter.rb~
|
139
|
-
- lib/ixtlan/babel/config.rb~
|
140
|
-
- lib/ixtlan/babel/serializer.rb
|
141
|
-
- spec/model_filter_with_methods.spec.rb~
|
142
|
-
- spec/model_filter_spec.rb~
|
143
122
|
- spec/model_filter_spec.rb
|
144
|
-
- spec/model_filter_with_methods_spec.rb~
|
145
123
|
- spec/params_filter_spec.rb
|
146
|
-
- spec/
|
124
|
+
- spec/model_filter_with_methods_spec.rb
|
147
125
|
- spec/hash_filter_spec.rb~
|
148
126
|
- spec/spec_helper.rb
|
149
|
-
- spec/
|
127
|
+
- spec/model_filter_with_methods.spec.rb~
|
150
128
|
- spec/params_filter_spec.rb~
|
129
|
+
- spec/hash_filter_spec.rb
|
130
|
+
- spec/model_filter_with_methods_spec.rb~
|
131
|
+
- spec/model_filter_spec.rb~
|
151
132
|
- MIT-LICENSE
|
152
133
|
- README.md
|
153
134
|
- Gemfile
|
@@ -181,5 +162,5 @@ summary: babel offers a filter for hashes and with that comes json/yaml/xml de/s
|
|
181
162
|
test_files:
|
182
163
|
- spec/model_filter_spec.rb
|
183
164
|
- spec/params_filter_spec.rb
|
184
|
-
- spec/hash_filter_spec.rb
|
185
165
|
- spec/model_filter_with_methods_spec.rb
|
166
|
+
- spec/hash_filter_spec.rb
|