build_associated 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/build_associated.rb +14 -6
- data/lib/build_associated/version.rb +1 -1
- metadata +3 -3
data/lib/build_associated.rb
CHANGED
@@ -5,13 +5,21 @@ module BuildAssociated
|
|
5
5
|
|
6
6
|
module ClassMethods
|
7
7
|
def build_associated association_name
|
8
|
-
|
9
|
-
|
8
|
+
begin
|
9
|
+
alias_method "_#{association_name}", association_name
|
10
|
+
remove_method(association_name)
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
define_method association_name do
|
13
|
+
obj = self.send("_#{association_name}") || super
|
14
|
+
obj ||= self.send("build_#{association_name}") unless self.frozen? or self.readonly?
|
15
|
+
return obj
|
16
|
+
end
|
17
|
+
rescue NameError
|
18
|
+
define_method association_name do
|
19
|
+
obj = super
|
20
|
+
obj ||= self.send("build_#{association_name}") unless self.frozen? or self.readonly?
|
21
|
+
return obj
|
22
|
+
end
|
15
23
|
end
|
16
24
|
end
|
17
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: build_associated
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-23 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &26988500 !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: *26988500
|
25
25
|
description: Have ActiveRecord automagically build an association when accessed. Useful
|
26
26
|
for belongs_to associations which should never be nil.
|
27
27
|
email:
|