rails_view_adapters 0.2.4 → 0.3.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56d420817b58d422d0515ae24e9dac93ed557a40
|
4
|
+
data.tar.gz: 81e9b580689665ae441a0192bc223a0dd91eb141
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4bdacb3c08cd35401e8c814d8f3451eabada3b311e1af7b7328379f0ece6a95d4355c7dd796540fd56d9e530203228f878d1de22b0eade57a3310c1e4ceb08d
|
7
|
+
data.tar.gz: 29f7f31c0249d57b89aaed0d90e3944eba06280855109a26a81a06f9825b16d4889871ba6c055abd4aaa501a1e27f46e6606edfcf210456fa461fa56e74692c6
|
@@ -94,18 +94,17 @@ module RailsViewAdapters
|
|
94
94
|
def map_belongs_to(model_field, public_field, options = {})
|
95
95
|
model_class = options[:model_class] || model_field.to_s.classify.constantize
|
96
96
|
sub_method = options[:sub_method] || :id
|
97
|
-
model_field_id = :"#{model_field.to_s.sub(/(_id|)\Z/, "_id")}"
|
98
97
|
|
99
98
|
unless options[:only] == :to
|
100
99
|
map_from_public public_field do |value|
|
101
100
|
record = model_class.send(:"find_by_#{sub_method}", value)
|
102
|
-
{
|
101
|
+
{ model_field => record ? record : model_class.new(sub_method => value) }
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
106
105
|
unless options[:only] == :from
|
107
|
-
map_to_public
|
108
|
-
{ public_field =>
|
106
|
+
map_to_public model_field do |record|
|
107
|
+
{ public_field => record.send(sub_method) }
|
109
108
|
end
|
110
109
|
end
|
111
110
|
end
|
@@ -190,13 +190,13 @@ module RailsViewAdapters
|
|
190
190
|
end
|
191
191
|
it "defines a to_map that converts the model's parent to the public's field:value string" do
|
192
192
|
proxy.map_belongs_to(model_field, public_field, options)
|
193
|
-
expect(proxy.map.to_maps[0][1].call(post.user
|
193
|
+
expect(proxy.map.to_maps[0][1].call(post.user))
|
194
194
|
.to eql(public_field => post.user.name)
|
195
195
|
end
|
196
|
-
it "defines a from_map that converts the public's string to the model's owning model
|
196
|
+
it "defines a from_map that converts the public's string to the model's owning model object" do
|
197
197
|
proxy.map_belongs_to(model_field, public_field, options)
|
198
198
|
expect(proxy.map.from_maps[0][1].call(post.user.name))
|
199
|
-
.to eql(model_field => post.user
|
199
|
+
.to eql(model_field => post.user)
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_view_adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Hockey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|