rails_view_adapters 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13e26a6b680a1fa4c5568fb1e5e445460534ea36
4
- data.tar.gz: 04142c6f2d5bc28b30cf4a6fe784be85f010d74f
3
+ metadata.gz: 56d420817b58d422d0515ae24e9dac93ed557a40
4
+ data.tar.gz: 81e9b580689665ae441a0192bc223a0dd91eb141
5
5
  SHA512:
6
- metadata.gz: 208e50ae487714b67bef56377a2416989618afdbf051452313d61145f1bc2243d28086ae394d5da926ac458734a3ebb26d0340f67de12b5c51d49b308c8c98d4
7
- data.tar.gz: a713a9fa0328e669827c4c169350aaaae61c21644eb78c8c786fbcf81d2127bda7de7e6b05778c7dd2297cc8c1651850d0960428c62ed103faeffe6cfeb834e5
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
- { model_field_id => record ? record.id : nil }
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 model_field_id do |id|
108
- { public_field => model_class.find_by(id: id).send(sub_method) }
106
+ map_to_public model_field do |record|
107
+ { public_field => record.send(sub_method) }
109
108
  end
110
109
  end
111
110
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module RailsViewAdapters
3
- VERSION = "0.2.4"
3
+ VERSION = "0.3.0"
4
4
  end
@@ -40,7 +40,7 @@ module RailsViewAdapters
40
40
  join_date: @model.join_date,
41
41
  admin: @model.admin,
42
42
  secret: @model.secret,
43
- team_id: @model.team_id,
43
+ team: @model.team,
44
44
  posts: @model.posts,
45
45
  created_at: @model.created_at,
46
46
  updated_at: @model.updated_at
@@ -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.id))
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 id" do
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.id)
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.2.4
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-04 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord