yaks 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.gitignore +1 -0
- data/.travis.yml +23 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +32 -6
- data/README.md +182 -80
- data/examples/hal01.rb +126 -0
- data/examples/jsonapi01.rb +68 -0
- data/examples/jsonapi02.rb +62 -0
- data/examples/jsonapi03.rb +86 -0
- data/lib/yaks.rb +55 -25
- data/lib/yaks/collection_mapper.rb +33 -0
- data/lib/yaks/collection_resource.rb +65 -0
- data/lib/yaks/default_policy.rb +13 -0
- data/lib/yaks/hal_serializer.rb +59 -0
- data/lib/yaks/json_api_serializer.rb +59 -0
- data/lib/yaks/link_lookup.rb +23 -0
- data/lib/yaks/mapper.rb +59 -0
- data/lib/yaks/mapper/association.rb +43 -0
- data/lib/yaks/mapper/class_methods.rb +36 -0
- data/lib/yaks/mapper/config.rb +79 -0
- data/lib/yaks/mapper/has_many.rb +15 -0
- data/lib/yaks/mapper/has_one.rb +10 -0
- data/lib/yaks/mapper/link.rb +74 -0
- data/lib/yaks/mapper/lookup.rb +19 -0
- data/lib/yaks/mapper/map_links.rb +17 -0
- data/lib/yaks/null_resource.rb +28 -0
- data/lib/yaks/primitivize.rb +34 -15
- data/lib/yaks/profile_registry.rb +60 -0
- data/lib/yaks/rel_registry.rb +20 -0
- data/lib/yaks/resource.rb +28 -0
- data/lib/yaks/resource/link.rb +21 -0
- data/lib/yaks/serializer.rb +11 -53
- data/lib/yaks/shared_options.rb +15 -0
- data/lib/yaks/util.rb +76 -5
- data/lib/yaks/version.rb +1 -1
- data/spec/integration/map_to_resource_spec.rb +30 -0
- data/spec/json/hal_plant_collection.json +34 -0
- data/spec/spec_helper.rb +10 -1
- data/spec/support/friends_mapper.rb +29 -0
- data/spec/support/pet_mapper.rb +5 -0
- data/spec/support/pet_peeve_mapper.rb +3 -0
- data/spec/support/serializers.rb +11 -11
- data/spec/support/shared_contexts.rb +47 -0
- data/spec/support/shorthands.rb +22 -0
- data/spec/yaks/collection_resource_spec.rb +9 -0
- data/spec/yaks/hal_serializer_spec.rb +9 -0
- data/spec/yaks/mapper/association_spec.rb +21 -0
- data/spec/yaks/mapper/class_methods_spec.rb +28 -0
- data/spec/yaks/mapper/config_spec.rb +77 -0
- data/spec/yaks/mapper/has_one_spec.rb +16 -0
- data/spec/yaks/mapper/link_spec.rb +42 -0
- data/spec/yaks/mapper/map_links_spec.rb +46 -0
- data/spec/yaks/mapper_spec.rb +47 -0
- data/spec/yaks/resource_spec.rb +23 -0
- data/yaks.gemspec +6 -3
- metadata +115 -27
- data/lib/yaks/dumper.rb +0 -23
- data/lib/yaks/fold_ams_compat.rb +0 -33
- data/lib/yaks/fold_json_api.rb +0 -61
- data/lib/yaks/serializable_association.rb +0 -21
- data/lib/yaks/serializable_collection.rb +0 -10
- data/lib/yaks/serializable_object.rb +0 -18
- data/lib/yaks/serializer/class_methods.rb +0 -76
- data/spec/integration_spec.rb +0 -57
- data/spec/yaks/json_api_folder_spec.rb +0 -63
- data/spec/yaks/serializer_spec.rb +0 -12
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yaks::Mapper do
|
4
|
+
include_context 'shorthands'
|
5
|
+
|
6
|
+
let(:mapper_class) { Class.new(Yaks::Mapper) }
|
7
|
+
let(:model) { Struct.new(:foo, :bar) }
|
8
|
+
let(:instance) { model.new('hello', 'world') }
|
9
|
+
|
10
|
+
context 'with attributes' do
|
11
|
+
before do
|
12
|
+
mapper_class.attributes :foo, :bar
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should make the configured attributes available on the instance' do
|
16
|
+
expect(mapper_class.new(Object.new).attributes).to eq Yaks::List(:foo, :bar)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'mapping attributes' do
|
20
|
+
it 'should load them from the model' do
|
21
|
+
expect(mapper_class.new(instance).map_attributes).to eq Yaks::List([:foo, 'hello'], [:bar, 'world'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'profile links' do
|
27
|
+
before do
|
28
|
+
mapper_class.profile :show
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with a dummy registry' do
|
32
|
+
it 'should create a link with the profile name as the uri' do
|
33
|
+
expect(mapper_class.new(instance).map_links).to eq Yaks::List(resource_link[:profile, 'show'])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with a registered profile' do
|
38
|
+
let(:registry) { Yaks::ProfileRegistry.create { profile :show, 'http://my.api/docs/show' } }
|
39
|
+
|
40
|
+
let(:mapper) { mapper_class.new(instance, profile_registry:registry) }
|
41
|
+
|
42
|
+
it 'should look up and use the correct uri' do
|
43
|
+
expect(mapper.map_links).to eq Yaks::List(resource_link[:profile, 'http://my.api/docs/show'])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yaks::Resource do
|
4
|
+
include_context 'shorthands'
|
5
|
+
|
6
|
+
let(:object) { described_class.new(attributes, links, subresources) }
|
7
|
+
let(:attributes) { {} }
|
8
|
+
let(:links) { [] }
|
9
|
+
let(:subresources) { {} }
|
10
|
+
|
11
|
+
describe '#uri' do
|
12
|
+
subject { object.uri }
|
13
|
+
|
14
|
+
context 'without a self link' do
|
15
|
+
it { should be_nil }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with a self link' do
|
19
|
+
let(:links) { [ resource_link[:self, '/foo/this_is_me/7'] ] }
|
20
|
+
it { should eq '/foo/this_is_me/7' }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/yaks.gemspec
CHANGED
@@ -17,12 +17,15 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = `git ls-files -- spec`.split($/)
|
18
18
|
gem.extra_rdoc_files = %w[README.md]
|
19
19
|
|
20
|
-
gem.add_runtime_dependency 'hamster'
|
21
|
-
gem.add_runtime_dependency 'inflection'
|
22
|
-
gem.add_runtime_dependency 'concord'
|
20
|
+
gem.add_runtime_dependency 'hamster' , '~> 0.4.3' # 128k , flog: 1851.8
|
21
|
+
gem.add_runtime_dependency 'inflection' , '~> 1.0.0' # 12k , flog: 226.8
|
22
|
+
gem.add_runtime_dependency 'concord' , '~> 0.1.4' # 8k , flog: 62.3
|
23
|
+
gem.add_runtime_dependency 'uri_template' , '~> 0.6.0' # 104k , flog: 1521.4
|
23
24
|
|
24
25
|
# For comparison, ActiveSupport has a flog score of 11134.7
|
25
26
|
|
26
27
|
gem.add_development_dependency 'virtus'
|
27
28
|
gem.add_development_dependency 'rspec'
|
29
|
+
gem.add_development_dependency 'coveralls'
|
30
|
+
gem.add_development_dependency 'rake'
|
28
31
|
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arne Brasseur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
prerelease: false
|
14
15
|
name: hamster
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
@@ -18,13 +19,13 @@ dependencies:
|
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: 0.4.3
|
20
21
|
type: :runtime
|
21
|
-
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.4.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
+
prerelease: false
|
28
29
|
name: inflection
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
@@ -32,13 +33,13 @@ dependencies:
|
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: 1.0.0
|
34
35
|
type: :runtime
|
35
|
-
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
+
prerelease: false
|
42
43
|
name: concord
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
@@ -46,38 +47,79 @@ dependencies:
|
|
46
47
|
- !ruby/object:Gem::Version
|
47
48
|
version: 0.1.4
|
48
49
|
type: :runtime
|
49
|
-
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.1.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
+
prerelease: false
|
57
|
+
name: uri_template
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.6.0
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.6.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
prerelease: false
|
56
71
|
name: virtus
|
57
72
|
requirement: !ruby/object:Gem::Requirement
|
58
73
|
requirements:
|
59
|
-
- - '>='
|
74
|
+
- - ! '>='
|
60
75
|
- !ruby/object:Gem::Version
|
61
76
|
version: '0'
|
62
77
|
type: :development
|
63
|
-
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - '>='
|
80
|
+
- - ! '>='
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
84
|
+
prerelease: false
|
70
85
|
name: rspec
|
71
86
|
requirement: !ruby/object:Gem::Requirement
|
72
87
|
requirements:
|
73
|
-
- - '>='
|
88
|
+
- - ! '>='
|
74
89
|
- !ruby/object:Gem::Version
|
75
90
|
version: '0'
|
76
91
|
type: :development
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
prerelease: false
|
99
|
+
name: coveralls
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
77
112
|
prerelease: false
|
113
|
+
name: rake
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
78
120
|
version_requirements: !ruby/object:Gem::Requirement
|
79
121
|
requirements:
|
80
|
-
- - '>='
|
122
|
+
- - ! '>='
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: '0'
|
83
125
|
description: Serialize to JSON-API and similar
|
@@ -89,28 +131,61 @@ extra_rdoc_files:
|
|
89
131
|
- README.md
|
90
132
|
files:
|
91
133
|
- .gitignore
|
134
|
+
- .travis.yml
|
92
135
|
- Gemfile
|
93
136
|
- Gemfile.lock
|
94
137
|
- README.md
|
138
|
+
- examples/hal01.rb
|
139
|
+
- examples/jsonapi01.rb
|
140
|
+
- examples/jsonapi02.rb
|
141
|
+
- examples/jsonapi03.rb
|
95
142
|
- lib/yaks.rb
|
96
|
-
- lib/yaks/
|
97
|
-
- lib/yaks/
|
98
|
-
- lib/yaks/
|
143
|
+
- lib/yaks/collection_mapper.rb
|
144
|
+
- lib/yaks/collection_resource.rb
|
145
|
+
- lib/yaks/default_policy.rb
|
146
|
+
- lib/yaks/hal_serializer.rb
|
147
|
+
- lib/yaks/json_api_serializer.rb
|
148
|
+
- lib/yaks/link_lookup.rb
|
149
|
+
- lib/yaks/mapper.rb
|
150
|
+
- lib/yaks/mapper/association.rb
|
151
|
+
- lib/yaks/mapper/class_methods.rb
|
152
|
+
- lib/yaks/mapper/config.rb
|
153
|
+
- lib/yaks/mapper/has_many.rb
|
154
|
+
- lib/yaks/mapper/has_one.rb
|
155
|
+
- lib/yaks/mapper/link.rb
|
156
|
+
- lib/yaks/mapper/lookup.rb
|
157
|
+
- lib/yaks/mapper/map_links.rb
|
158
|
+
- lib/yaks/null_resource.rb
|
99
159
|
- lib/yaks/primitivize.rb
|
100
|
-
- lib/yaks/
|
101
|
-
- lib/yaks/
|
102
|
-
- lib/yaks/
|
160
|
+
- lib/yaks/profile_registry.rb
|
161
|
+
- lib/yaks/rel_registry.rb
|
162
|
+
- lib/yaks/resource.rb
|
163
|
+
- lib/yaks/resource/link.rb
|
103
164
|
- lib/yaks/serializer.rb
|
104
|
-
- lib/yaks/
|
165
|
+
- lib/yaks/shared_options.rb
|
105
166
|
- lib/yaks/util.rb
|
106
167
|
- lib/yaks/version.rb
|
107
|
-
- spec/
|
168
|
+
- spec/integration/map_to_resource_spec.rb
|
169
|
+
- spec/json/hal_plant_collection.json
|
108
170
|
- spec/spec_helper.rb
|
109
171
|
- spec/support/fixtures.rb
|
172
|
+
- spec/support/friends_mapper.rb
|
110
173
|
- spec/support/models.rb
|
174
|
+
- spec/support/pet_mapper.rb
|
175
|
+
- spec/support/pet_peeve_mapper.rb
|
111
176
|
- spec/support/serializers.rb
|
112
|
-
- spec/
|
113
|
-
- spec/
|
177
|
+
- spec/support/shared_contexts.rb
|
178
|
+
- spec/support/shorthands.rb
|
179
|
+
- spec/yaks/collection_resource_spec.rb
|
180
|
+
- spec/yaks/hal_serializer_spec.rb
|
181
|
+
- spec/yaks/mapper/association_spec.rb
|
182
|
+
- spec/yaks/mapper/class_methods_spec.rb
|
183
|
+
- spec/yaks/mapper/config_spec.rb
|
184
|
+
- spec/yaks/mapper/has_one_spec.rb
|
185
|
+
- spec/yaks/mapper/link_spec.rb
|
186
|
+
- spec/yaks/mapper/map_links_spec.rb
|
187
|
+
- spec/yaks/mapper_spec.rb
|
188
|
+
- spec/yaks/resource_spec.rb
|
114
189
|
- yaks.gemspec
|
115
190
|
homepage: https://github.com/plexus/yaks
|
116
191
|
licenses:
|
@@ -122,26 +197,39 @@ require_paths:
|
|
122
197
|
- lib
|
123
198
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
199
|
requirements:
|
125
|
-
- - '>='
|
200
|
+
- - ! '>='
|
126
201
|
- !ruby/object:Gem::Version
|
127
202
|
version: '0'
|
128
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
204
|
requirements:
|
130
|
-
- - '>='
|
205
|
+
- - ! '>='
|
131
206
|
- !ruby/object:Gem::Version
|
132
207
|
version: '0'
|
133
208
|
requirements: []
|
134
209
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.
|
210
|
+
rubygems_version: 2.2.1
|
136
211
|
signing_key:
|
137
212
|
specification_version: 4
|
138
213
|
summary: Serialize to JSON-API and similar
|
139
214
|
test_files:
|
140
|
-
- spec/
|
215
|
+
- spec/integration/map_to_resource_spec.rb
|
216
|
+
- spec/json/hal_plant_collection.json
|
141
217
|
- spec/spec_helper.rb
|
142
218
|
- spec/support/fixtures.rb
|
219
|
+
- spec/support/friends_mapper.rb
|
143
220
|
- spec/support/models.rb
|
221
|
+
- spec/support/pet_mapper.rb
|
222
|
+
- spec/support/pet_peeve_mapper.rb
|
144
223
|
- spec/support/serializers.rb
|
145
|
-
- spec/
|
146
|
-
- spec/
|
147
|
-
|
224
|
+
- spec/support/shared_contexts.rb
|
225
|
+
- spec/support/shorthands.rb
|
226
|
+
- spec/yaks/collection_resource_spec.rb
|
227
|
+
- spec/yaks/hal_serializer_spec.rb
|
228
|
+
- spec/yaks/mapper/association_spec.rb
|
229
|
+
- spec/yaks/mapper/class_methods_spec.rb
|
230
|
+
- spec/yaks/mapper/config_spec.rb
|
231
|
+
- spec/yaks/mapper/has_one_spec.rb
|
232
|
+
- spec/yaks/mapper/link_spec.rb
|
233
|
+
- spec/yaks/mapper/map_links_spec.rb
|
234
|
+
- spec/yaks/mapper_spec.rb
|
235
|
+
- spec/yaks/resource_spec.rb
|
data/lib/yaks/dumper.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Yaks
|
2
|
-
class Dumper
|
3
|
-
include Util
|
4
|
-
|
5
|
-
def initialize(options = {})
|
6
|
-
@lookup = options.fetch(:serializer_lookup) { Yaks.default_serializer_lookup }
|
7
|
-
format = options.fetch(:format) { :json_api }
|
8
|
-
@format = Yaks.const_get("Fold#{camelize(format.to_s)}") if format.is_a?(Symbol)
|
9
|
-
@options = options
|
10
|
-
end
|
11
|
-
|
12
|
-
def dump(type, objects)
|
13
|
-
serializer = @lookup.(type).new(@options.merge(root_key: type))
|
14
|
-
Primitivize.(
|
15
|
-
@format.new(
|
16
|
-
serializer.serializable_collection(objects)
|
17
|
-
).fold
|
18
|
-
)
|
19
|
-
end
|
20
|
-
alias call dump
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
data/lib/yaks/fold_ams_compat.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module Yaks
|
2
|
-
class FoldAmsCompat < FoldJsonApi
|
3
|
-
include Concord.new(:collection)
|
4
|
-
include Util
|
5
|
-
extend Forwardable
|
6
|
-
|
7
|
-
def_delegator :collection, :root_key
|
8
|
-
|
9
|
-
def fold
|
10
|
-
Hamster.hash(
|
11
|
-
root_key => collection.map(&method(:fold_object)),
|
12
|
-
).merge(
|
13
|
-
fold_associated_objects
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def fold_object(object)
|
20
|
-
object.attributes.merge(link_ids(object))
|
21
|
-
end
|
22
|
-
|
23
|
-
def fold_association_ids(hash, association)
|
24
|
-
name = singular(association.name.to_s)
|
25
|
-
if association.one?
|
26
|
-
hash.put(name + '_id', association.identities.first)
|
27
|
-
else
|
28
|
-
hash.put(name + '_ids', association.identities)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
data/lib/yaks/fold_json_api.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
module Yaks
|
2
|
-
class FoldJsonApi
|
3
|
-
include Concord.new(:collection)
|
4
|
-
include Util
|
5
|
-
extend Forwardable
|
6
|
-
|
7
|
-
def_delegator :collection, :root_key
|
8
|
-
|
9
|
-
def fold
|
10
|
-
Hamster.hash(
|
11
|
-
root_key => collection.map(&method(:fold_object)),
|
12
|
-
"linked" => fold_associated_objects
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def fold_object(object)
|
19
|
-
if object.has_associated_objects?
|
20
|
-
object.attributes.merge(Hamster.hash(links: link_ids(object)))
|
21
|
-
else
|
22
|
-
object.attributes
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def link_ids(object)
|
27
|
-
object.associations.reduce(
|
28
|
-
Hamster.hash,
|
29
|
-
&method(:fold_association_ids)
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
def fold_association_ids(hash, association)
|
34
|
-
if association.one?
|
35
|
-
hash.put(association.name, association.identities.first)
|
36
|
-
else
|
37
|
-
hash.put(association.name, association.identities)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def fold_associated_objects
|
42
|
-
association_names = Hamster.set(*
|
43
|
-
collection.flat_map do |object|
|
44
|
-
object.associations.map{|ass| [ass.name, ass.one?] }
|
45
|
-
end
|
46
|
-
)
|
47
|
-
Hamster.hash(
|
48
|
-
association_names.map do |name, one|
|
49
|
-
[
|
50
|
-
one ? pluralize(name.to_s) : name,
|
51
|
-
Hamster.set(*
|
52
|
-
collection.flat_map do |object|
|
53
|
-
object.associated_objects(name)
|
54
|
-
end
|
55
|
-
).map(&method(:fold_object))
|
56
|
-
]
|
57
|
-
end
|
58
|
-
)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|