polymorpheus 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/polymorpheus/interface.rb +6 -1
- data/lib/polymorpheus/version.rb +1 -1
- data/spec/interface_spec.rb +7 -0
- metadata +4 -4
@@ -54,8 +54,13 @@ module Polymorpheus
|
|
54
54
|
# Getter method
|
55
55
|
define_method polymorphic_api do
|
56
56
|
if key = self.send("#{polymorphic_api}_active_key")
|
57
|
+
# we are connecting to an existing item in the db
|
57
58
|
self.send key.gsub(/_id$/,'')
|
58
|
-
|
59
|
+
else
|
60
|
+
# we can also link to a new record if we're careful
|
61
|
+
objs = associations.map { |association| self.send(association) }.compact
|
62
|
+
objs.first if objs.length == 1
|
63
|
+
end
|
59
64
|
end
|
60
65
|
|
61
66
|
# Setter method
|
data/lib/polymorpheus/version.rb
CHANGED
data/spec/interface_spec.rb
CHANGED
@@ -70,6 +70,13 @@ describe Shoe do
|
|
70
70
|
let(:attributes) { { man: man } }
|
71
71
|
it_should_behave_like "valid polymorphic relationship"
|
72
72
|
end
|
73
|
+
context "and the record we are linking to is a new record" do
|
74
|
+
let(:new_man) { Man.new }
|
75
|
+
let(:attributes) { { man: new_man } }
|
76
|
+
specify { shoe.wearer.should == new_man }
|
77
|
+
specify { shoe.wearer_active_key.should be_nil }
|
78
|
+
specify { shoe.wearer_query_condition.should be_nil }
|
79
|
+
end
|
73
80
|
end
|
74
81
|
|
75
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polymorpheus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: foreigner
|
16
|
-
requirement: &
|
16
|
+
requirement: &70363112837300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70363112837300
|
25
25
|
description: Provides a database-friendly method for polymorphic relationships
|
26
26
|
email: bsingh@wegowise.com
|
27
27
|
executables: []
|