Module: ActsAsReplaceable::ActMethod
- Defined in:
- lib/acts_as_replaceable/acts_as_replaceable.rb
Instance Method Summary collapse
-
#acts_as_replaceable(options = {}) ⇒ Object
If any before_save methods change the attributes, acts_as_replaceable will not function correctly.
Instance Method Details
#acts_as_replaceable(options = {}) ⇒ Object
If any before_save methods change the attributes, acts_as_replaceable will not function correctly.
OPTIONS :match => what fields to match against when finding a duplicate :insensitive_match => what fields to do case insensitive matching on. :inherit => what attributes of the existing record overwrite our own attributes
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/acts_as_replaceable/acts_as_replaceable.rb', line 13 def acts_as_replaceable( = {}) extend ActsAsReplaceable::ClassMethods include ActsAsReplaceable::InstanceMethods attr_reader :has_been_replaced cattr_accessor :acts_as_replaceable_options .symbolize_keys! self. = {} self.[:match] = ActsAsReplaceable::HelperMethods.sanitize_attribute_names(self, [:match]) self.[:insensitive_match] = ActsAsReplaceable::HelperMethods.sanitize_attribute_names(self, [:insensitive_match]) self.[:inherit] = ActsAsReplaceable::HelperMethods.sanitize_attribute_names(self, [:inherit], [:insensitive_match], :id, :created_at, :updated_at) if ActsAsReplaceable.concurrency && !Rails.cache.respond_to?(:increment) raise LockingUnavailable, "To run ActsAsReplaceable in concurrency mode, the Rails cache must provide an :increment method that performs an atomic addition to the given key, e.g. Memcached" end end |