Skip to content

Commit

Permalink
Quick hack to get it to work with rails 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ajrkerr committed Jan 23, 2012
1 parent 4bab724 commit 49f0705
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions lib/build_associated.rb
Expand Up @@ -5,13 +5,21 @@ module BuildAssociated

module ClassMethods
def build_associated association_name
alias_method "_#{association_name}", association_name
remove_method association_name
begin
alias_method "_#{association_name}", association_name
remove_method(association_name)

define_method association_name do
obj = self.send("_#{association_name}")
obj ||= self.send("build_#{association_name}") unless self.frozen? or self.readonly?
return obj
define_method association_name do
obj = self.send("_#{association_name}") || super
obj ||= self.send("build_#{association_name}") unless self.frozen? or self.readonly?
return obj
end
rescue NameError
define_method association_name do
obj = super
obj ||= self.send("build_#{association_name}") unless self.frozen? or self.readonly?
return obj
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/build_associated/version.rb
@@ -1,3 +1,3 @@
module BuildAssociated
VERSION = "1.0.1"
VERSION = "1.1.2"
end

0 comments on commit 49f0705

Please sign in to comment.