optimisations, and some fixes for ruby 1.8.7
This commit is contained in:
parent
2a9305ebd3
commit
3ad4e1e979
5 changed files with 47 additions and 34 deletions
|
@ -62,6 +62,7 @@ module CouchRest::Model
|
|||
super
|
||||
end
|
||||
|
||||
# ruby 1.9
|
||||
def keep_if
|
||||
if use_dirty? && block_given?
|
||||
self.keys.each do |key|
|
||||
|
|
|
@ -22,7 +22,7 @@ module CouchRest
|
|||
|
||||
def use_dirty?
|
||||
bdoc = base_doc
|
||||
bdoc && !bdoc.disable_dirty && bdoc.use_dirty
|
||||
bdoc && bdoc.use_dirty && !bdoc.disable_dirty
|
||||
end
|
||||
|
||||
def couchrest_attribute_will_change!(attr)
|
||||
|
|
|
@ -6,7 +6,9 @@ module CouchRest
|
|||
|
||||
included do
|
||||
extlib_inheritable_accessor(:properties) unless self.respond_to?(:properties)
|
||||
extlib_inheritable_accessor(:prop_by_name) unless self.respond_to?(:prop_by_name)
|
||||
self.properties ||= []
|
||||
self.prop_by_name ||= {}
|
||||
raise "You can only mixin Properties in a class responding to [] and []=, if you tried to mixin CastedModel, make sure your class inherits from Hash or responds to the proper methods" unless (method_defined?(:[]) && method_defined?(:[]=))
|
||||
end
|
||||
|
||||
|
@ -88,7 +90,7 @@ module CouchRest
|
|||
alias :attributes :properties_with_values
|
||||
|
||||
def find_property(property)
|
||||
property.is_a?(Property) ? property : self.class.properties.detect {|p| p.to_s == property.to_s}
|
||||
property.is_a?(Property) ? property : self.class.prop_by_name[property.to_s]
|
||||
end
|
||||
|
||||
# The following methods should be accessable by the Model::Base Class, but not by anything else!
|
||||
|
@ -208,6 +210,7 @@ module CouchRest
|
|||
validates_casted_model property.name
|
||||
end
|
||||
properties << property
|
||||
prop_by_name[property.to_s] = property
|
||||
property
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue