Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Do not extend a Model more than one time
Browse files Browse the repository at this point in the history
* This prevents clobbering of properties and other ivars set in the
  model when extended
* Check for the existence of previously named properties in a
  cleaner/simpler way
  • Loading branch information
dkubb committed May 16, 2009
1 parent 65c1174 commit 10d2a7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/dm-core/model.rb
Expand Up @@ -113,6 +113,8 @@ def self.extra_extensions
# TODO: document
# @api private
def self.extended(model)
return if Model.descendants.include?(model)

unless model.ancestors.include?(Resource)
model.send(:include, Resource)
end
Expand Down
12 changes: 9 additions & 3 deletions lib/dm-core/property_set.rb
Expand Up @@ -16,12 +16,14 @@ def [](name)
@properties[name]
end

alias super_slice []=

# TODO: document
# @api semipublic
def []=(name, property)
if named?(name)
add_property(property)
map! { |p| p == property || p.name == property.name ? property : p }
super_slice(index(property), property)
else
self << property
end
Expand All @@ -42,8 +44,12 @@ def values_at(*names)
# TODO: document
# @api semipublic
def <<(property)
add_property(property)
super
if named?(property.name)
super_slice(index(property), property)
else
add_property(property)
super
end
end

# TODO: document
Expand Down

0 comments on commit 10d2a7f

Please sign in to comment.