removed use_dirty config option (runs faster)
This commit is contained in:
parent
3ad4e1e979
commit
634813858e
9 changed files with 11 additions and 79 deletions
|
@ -21,7 +21,7 @@ module CouchRest::Model
|
|||
end
|
||||
|
||||
def []= key, value
|
||||
couchrest_attribute_will_change!(key) if use_dirty && self[key] != value
|
||||
couchrest_attribute_will_change!(key) if self[key] != value
|
||||
super(key.to_s, value)
|
||||
end
|
||||
|
||||
|
|
|
@ -10,12 +10,10 @@ module CouchRest
|
|||
included do
|
||||
add_config :model_type_key
|
||||
add_config :mass_assign_any_attribute
|
||||
add_config :use_dirty
|
||||
|
||||
configure do |config|
|
||||
config.model_type_key = 'couchrest-type' # 'model'?
|
||||
config.mass_assign_any_attribute = false
|
||||
config.use_dirty = true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ module CouchRest
|
|||
|
||||
def use_dirty?
|
||||
bdoc = base_doc
|
||||
bdoc && bdoc.use_dirty && !bdoc.disable_dirty
|
||||
bdoc && !bdoc.disable_dirty
|
||||
end
|
||||
|
||||
def couchrest_attribute_will_change!(attr)
|
||||
|
|
|
@ -30,7 +30,7 @@ module CouchRest
|
|||
def update(options = {})
|
||||
raise "Calling #{self.class.name}#update on document that has not been created!" if self.new?
|
||||
return false unless perform_validations(options)
|
||||
return true if use_dirty? && !self.changed?
|
||||
return true if !self.changed?
|
||||
_run_update_callbacks do
|
||||
_run_save_callbacks do
|
||||
result = database.save_doc(self)
|
||||
|
|
|
@ -203,7 +203,7 @@ module CouchRest
|
|||
end
|
||||
type = [type] # inject as an array
|
||||
end
|
||||
property = Property.new(name, type, options.merge(:use_dirty => use_dirty))
|
||||
property = Property.new(name, type, options)
|
||||
create_property_getter(property)
|
||||
create_property_setter(property) unless property.read_only == true
|
||||
if property.type_class.respond_to?(:validates_casted_model)
|
||||
|
|
|
@ -4,7 +4,7 @@ module CouchRest::Model
|
|||
|
||||
include ::CouchRest::Model::Typecast
|
||||
|
||||
attr_reader :name, :type, :type_class, :read_only, :alias, :default, :casted, :init_method, :use_dirty, :options
|
||||
attr_reader :name, :type, :type_class, :read_only, :alias, :default, :casted, :init_method, :options
|
||||
|
||||
# Attribute to define.
|
||||
# All Properties are assumed casted unless the type is nil.
|
||||
|
@ -38,8 +38,8 @@ module CouchRest::Model
|
|||
end
|
||||
arr = value.collect { |data| cast_value(parent, data) }
|
||||
# allow casted_by calls to be passed up chain by wrapping in CastedArray
|
||||
value = (use_dirty || type_class != String) ? CastedArray.new(arr, self) : arr
|
||||
value.casted_by = parent if value.respond_to?(:casted_by)
|
||||
value = CastedArray.new(arr, self)
|
||||
value.casted_by = parent
|
||||
elsif (type == Object || type == Hash) && (value.class == Hash)
|
||||
# allow casted_by calls to be passed up chain by wrapping in CastedHash
|
||||
value = CouchRest::Model::CastedHash[value]
|
||||
|
@ -94,7 +94,6 @@ module CouchRest::Model
|
|||
@alias = options.delete(:alias) if options[:alias]
|
||||
@default = options.delete(:default) unless options[:default].nil?
|
||||
@init_method = options[:init_method] ? options.delete(:init_method) : 'new'
|
||||
@use_dirty = options.delete(:use_dirty)
|
||||
@options = options
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue