ixtlan-babel 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/README.md +18 -0
- data/lib/ixtlan/babel/filter_config.rb +2 -2
- data/spec/model_filter_spec.rb +36 -12
- metadata +85 -52
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ixtlan-babel (0.1
|
4
|
+
ixtlan-babel (0.2.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
@@ -9,7 +9,7 @@ GEM
|
|
9
9
|
backports (2.6.2)
|
10
10
|
json_pure (1.6.1)
|
11
11
|
minitest (4.3.2)
|
12
|
-
rake (10.0.
|
12
|
+
rake (10.0.3)
|
13
13
|
virtus (0.5.1)
|
14
14
|
backports (~> 2.6.1)
|
15
15
|
|
data/README.md
CHANGED
@@ -11,3 +11,21 @@ the first problem I had was that I needed serveral options map at different cont
|
|
11
11
|
the next problem was that I could include the result of a given method with `:methods => ['age']` but only on the root level of the object tree. but if I wanted to `age` method to be part of the serialization somewhere deep inside the object tree, it is not possible.
|
12
12
|
|
13
13
|
please have a look at **spec/filter_spec.rb** how to use it :)
|
14
|
+
|
15
|
+
TODO usage
|
16
|
+
==========
|
17
|
+
|
18
|
+
Contributing
|
19
|
+
------------
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
26
|
+
|
27
|
+
meta-fu
|
28
|
+
-------
|
29
|
+
|
30
|
+
enjoy :)
|
31
|
+
|
@@ -38,11 +38,11 @@ module Ixtlan
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def single_options( context_or_options )
|
41
|
-
context_options( context_or_options ) || context[default_context_key[0]] || {}
|
41
|
+
context_options( context_or_options ) || context[ default_context_key[ 0 ] ] || {}
|
42
42
|
end
|
43
43
|
|
44
44
|
def collection_options( context_or_options )
|
45
|
-
context_options( context_or_options ) || context[default_context_key[1]] || {}
|
45
|
+
context_options( context_or_options ) || context[ default_context_key[ 1 ] ] || {}
|
46
46
|
end
|
47
47
|
|
48
48
|
attr_accessor :root
|
data/spec/model_filter_spec.rb
CHANGED
@@ -49,14 +49,20 @@ describe Ixtlan::Babel::ModelFilter do
|
|
49
49
|
it 'should serialize and deserialize without root' do
|
50
50
|
json = serializer.to_json
|
51
51
|
result = deserializer.from_json(json)
|
52
|
-
|
52
|
+
|
53
|
+
# travis produces [] and locally there is a nil - filter empty as well :(
|
54
|
+
attributes = result.attributes.delete_if { |k,v| v.nil? || v.empty? }
|
55
|
+
|
53
56
|
attributes.must_equal Hash[:id => person['id'], :name => person['name']]
|
54
57
|
end
|
55
58
|
|
56
59
|
it 'should serialize and deserialize with root' do
|
57
60
|
json = serializer.to_json :root => 'my'
|
58
61
|
result = deserializer.from_json(json, :root => 'my')
|
59
|
-
|
62
|
+
|
63
|
+
# travis produces [] and locally there is a nil - filter empty as well :(
|
64
|
+
attributes = result.attributes.delete_if { |k,v| v.nil? || v.empty? }
|
65
|
+
|
60
66
|
attributes.must_equal Hash[:id => person['id'], :name => person['name']]
|
61
67
|
end
|
62
68
|
|
@@ -72,20 +78,34 @@ describe Ixtlan::Babel::ModelFilter do
|
|
72
78
|
result.id.must_equal person.id
|
73
79
|
end
|
74
80
|
|
75
|
-
it '
|
81
|
+
it 'should serialize and deserialize with except' do
|
76
82
|
json = serializer.to_json(:except => ['id'])
|
77
83
|
result = deserializer.from_json(json, :except => ['id'])
|
78
|
-
|
79
|
-
|
80
|
-
result.attributes
|
84
|
+
|
85
|
+
# travis sees empty array and locally it is nil :(
|
86
|
+
result.attributes[ :phone_numbers ] ||= []
|
87
|
+
result.attributes.must_equal Hash[:name => person['name'], :address=>nil, :phone_numbers=>[], :id => nil]
|
88
|
+
|
89
|
+
result = deserializer.from_json(json)
|
90
|
+
|
91
|
+
# travis sees empty array and locally it is nil :(
|
92
|
+
result.attributes[ :phone_numbers ] ||= []
|
93
|
+
result.attributes.must_equal Hash[:name => person['name'], :address=>nil, :phone_numbers=>[], :id => nil]
|
81
94
|
end
|
82
95
|
|
83
96
|
it 'should serialize and deserialize with only' do
|
84
97
|
json = serializer.to_json(:only => ['name'])
|
85
98
|
result = deserializer.from_json(json, :only => ['name'])
|
86
|
-
|
99
|
+
|
100
|
+
# travis sees empty array and locally it is nil :(
|
101
|
+
result.attributes[ :phone_numbers ] ||= []
|
102
|
+
result.attributes.must_equal Hash[:name => person['name'], :address=>nil, :phone_numbers=>[], :id => nil]
|
103
|
+
|
87
104
|
result = deserializer.from_json(json)
|
88
|
-
|
105
|
+
|
106
|
+
# travis sees empty array and locally it is nil :(
|
107
|
+
result.attributes[ :phone_numbers ] ||= []
|
108
|
+
result.attributes.must_equal Hash[:name => person['name'], :address=>nil, :phone_numbers=>[], :id => nil]
|
89
109
|
end
|
90
110
|
|
91
111
|
it 'should serialize and deserialize with nested only' do
|
@@ -95,7 +115,8 @@ describe Ixtlan::Babel::ModelFilter do
|
|
95
115
|
json['phone_numbers'].must_be_nil
|
96
116
|
json['address']['zipcode'].must_be_nil
|
97
117
|
|
98
|
-
|
118
|
+
# travis produces [] and locally there is a nil :(
|
119
|
+
(result.phone_numbers || []).must_equal []
|
99
120
|
|
100
121
|
result.address.zipcode.must_be_nil
|
101
122
|
|
@@ -110,7 +131,8 @@ describe Ixtlan::Babel::ModelFilter do
|
|
110
131
|
json['phone_numbers'].must_be_nil
|
111
132
|
json['address']['zipcode'].must_be_nil
|
112
133
|
|
113
|
-
|
134
|
+
# travis produces [] and locally there is a nil :(
|
135
|
+
(result.phone_numbers || []).must_equal []
|
114
136
|
|
115
137
|
result.address.zipcode.must_be_nil
|
116
138
|
|
@@ -125,7 +147,8 @@ describe Ixtlan::Babel::ModelFilter do
|
|
125
147
|
json['phone_numbers'].must_be_nil
|
126
148
|
json['address']['zipcode'].must_be_nil
|
127
149
|
|
128
|
-
|
150
|
+
# travis produces [] and locally there is a nil :(
|
151
|
+
(result.phone_numbers || []).must_equal []
|
129
152
|
|
130
153
|
result.address.zipcode.must_be_nil
|
131
154
|
|
@@ -140,7 +163,8 @@ describe Ixtlan::Babel::ModelFilter do
|
|
140
163
|
json['phone_numbers'].must_be_nil
|
141
164
|
json['address']['zipcode'].must_be_nil
|
142
165
|
|
143
|
-
|
166
|
+
# travis produces [] and locally there is a nil :(
|
167
|
+
(result.phone_numbers || []).must_equal []
|
144
168
|
|
145
169
|
result.address.zipcode.must_be_nil
|
146
170
|
|
metadata
CHANGED
@@ -1,69 +1,95 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ixtlan-babel
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Kristian Meier
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2012-12-29 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: rake
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
25
|
+
requirements:
|
19
26
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 79
|
29
|
+
segments:
|
30
|
+
- 10
|
31
|
+
- 0
|
32
|
+
- 0
|
21
33
|
version: 10.0.0
|
22
34
|
type: :development
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
26
37
|
name: json_pure
|
27
|
-
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
40
|
none: false
|
29
|
-
requirements:
|
41
|
+
requirements:
|
30
42
|
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 6
|
48
|
+
version: "1.6"
|
33
49
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
37
52
|
name: minitest
|
38
|
-
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
55
|
none: false
|
40
|
-
requirements:
|
56
|
+
requirements:
|
41
57
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 51
|
60
|
+
segments:
|
61
|
+
- 4
|
62
|
+
- 3
|
63
|
+
- 0
|
43
64
|
version: 4.3.0
|
44
65
|
type: :development
|
45
|
-
|
46
|
-
|
47
|
-
- !ruby/object:Gem::Dependency
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
48
68
|
name: virtus
|
49
|
-
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
71
|
none: false
|
51
|
-
requirements:
|
72
|
+
requirements:
|
52
73
|
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 11
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
- 5
|
79
|
+
- 0
|
54
80
|
version: 0.5.0
|
55
81
|
type: :development
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
of models which provides a hash representationi. possible models are activerecord,
|
60
|
-
activemodel, resources from datamapper, virtus
|
61
|
-
email:
|
82
|
+
version_requirements: *id004
|
83
|
+
description: babel offers a filter for hashes and with that comes json/yaml/xml de/serialization of models which provides a hash representationi. possible models are activerecord, activemodel, resources from datamapper, virtus
|
84
|
+
email:
|
62
85
|
- m.kristian@web.de
|
63
86
|
executables: []
|
87
|
+
|
64
88
|
extensions: []
|
89
|
+
|
65
90
|
extra_rdoc_files: []
|
66
|
-
|
91
|
+
|
92
|
+
files:
|
67
93
|
- lib/ixtlan-babel.rb
|
68
94
|
- lib/ixtlan/babel/deserializer.rb
|
69
95
|
- lib/ixtlan/babel/hash_filter.rb
|
@@ -96,31 +122,38 @@ files:
|
|
96
122
|
- Gemfile.lock
|
97
123
|
homepage: https://github.com/mkristian/ixtlan-babel
|
98
124
|
licenses: []
|
125
|
+
|
99
126
|
post_install_message:
|
100
127
|
rdoc_options: []
|
101
|
-
|
128
|
+
|
129
|
+
require_paths:
|
102
130
|
- lib
|
103
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
132
|
none: false
|
105
|
-
requirements:
|
106
|
-
- -
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
|
109
|
-
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
hash: 3
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
version: "0"
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
141
|
none: false
|
111
|
-
requirements:
|
112
|
-
- -
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 3
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
version: "0"
|
115
149
|
requirements: []
|
150
|
+
|
116
151
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.8.
|
152
|
+
rubygems_version: 1.8.15
|
118
153
|
signing_key:
|
119
154
|
specification_version: 3
|
120
|
-
summary: babel offers a filter for hashes and with that comes json/yaml/xml de/serialization
|
121
|
-
|
122
|
-
test_files:
|
155
|
+
summary: babel offers a filter for hashes and with that comes json/yaml/xml de/serialization of models which provides a hash representation
|
156
|
+
test_files:
|
123
157
|
- spec/model_filter_spec.rb
|
124
158
|
- spec/hash_filter_spec.rb
|
125
159
|
- spec/model_filter_with_methods_spec.rb
|
126
|
-
has_rdoc:
|