nested 0.0.30 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nested/one.rb +13 -3
  3. data/nested.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2dc4320c86fbb50e5eb18ba56f3e0586eebdf59
4
- data.tar.gz: 5a317c9502f9e660ff115d1ae2082427f8487651
3
+ metadata.gz: 39e26e8bb789f663b4e690fa556817ae758e1ae4
4
+ data.tar.gz: a224aafd80bde5b8c5c4f8979e87e30fddd3f6af
5
5
  SHA512:
6
- metadata.gz: 8cee76f95bcb3362c969b6a4ed8521d23f5954fd2693b36be368a11fd90a917d1299a29ff517ceea4d244a63fe3985152461739ca0304726f98e0bf6765d86ca
7
- data.tar.gz: e655d4103dbe7824ebd3c870f5a5d582fdc9f5fcad1acdd60026565569624c6d8b28d4f7964a63ad6cfbef0f8b0aec84b665d6c4f08ef33828ff5b3bda36e451
6
+ metadata.gz: bbc5966672e6de113a9423635bf194da353f06f3b82ad143f5e5a4dc4f44165c2db7c1599cdd00b57bda46cfea90cef1056e841f17fae96c57f2e882fa9a5de1
7
+ data.tar.gz: 761f3d7b3a4dd96beea705d63d597a0956f1620761ef6e91a432a6be1208061bf727e2fe4e1fbf09a2b18b90008222e094810d03d8c1420b91fb81484e55963b
data/lib/nested/one.rb CHANGED
@@ -4,9 +4,19 @@ module Nested
4
4
 
5
5
  MODEL_BLOCK = Proc.new do
6
6
  if @__resource.parent
7
- instance_variable_get("@#{@__resource.parent.instance_variable_name}")
8
- .where(id: params[:"#{@__resource.parent.name.to_s.singularize.to_sym}_id"])
9
- .first
7
+ parent_model = instance_variable_get("@#{@__resource.parent.instance_variable_name}")
8
+
9
+ if parent_model.respond_to?(:where)
10
+ parent_model
11
+ .where(id: params[:"#{@__resource.parent.name.to_s.singularize.to_sym}_id"])
12
+ .first
13
+ elsif parent_model.respond_to?(:detect)
14
+ parent_model.detect do |r|
15
+ (r.is_a?(Hash) ? HashWithIndifferentAccess.new(r)[:id] : r.id).to_s == params[:"#{@__resource.parent.name.to_s.singularize.to_sym}_id"]
16
+ end
17
+ else
18
+ nil
19
+ end
10
20
  else
11
21
  nil
12
22
  end
data/nested.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "nested"
3
- s.version = "0.0.30"
3
+ s.version = "0.0.31"
4
4
 
5
5
  s.authors = ["Jan Zimmek"]
6
6
  s.email = %q{jan.zimmek@web.de}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nested
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Zimmek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-09 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport