Sha256: 0d09504f9a3708927acd3983fdcf09c2d28330c7f83ee59296bade81469a6cb7

Contents?: true

Size: 1.08 KB

Versions: 27

Compression:

Stored size: 1.08 KB

Contents

module Alchemy
  module Touching

    # Touches the timestamps and userstamps
    #
    def touch
      # Using update here, because we want the touch call to bubble up to the page.
      update(touchable_attributes)
    end

    private

    # If the model has a +contents+ association,
    # it updates all their timestamps.
    #
    # CAUTION: Only use on bottom to top releations,
    # e.g. +Alchemy::Picture+ or +Alchemy::Attachment+
    # not on top to bottom ones like +Alchemy::Element+.
    #
    def touch_contents
      return unless self.respond_to?(:contents)
      self.contents.update_all(touchable_attributes)
    end

    # If the model has a +touchable_pages+ association,
    # it updates all their timestamps.
    #
    # Used by +Alchemy::Element+
    #
    def touch_pages
      return unless self.respond_to?(:touchable_pages)
      self.touchable_pages.update_all(touchable_attributes)
    end

    # Returns the attributes hash for touching a model.
    #
    def touchable_attributes
      {updated_at: Time.now, updater_id: Alchemy.user_class.try(:stamper)}
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
alchemy_cms-3.2.1 lib/alchemy/touching.rb
alchemy_cms-3.1.3 lib/alchemy/touching.rb
lc_alchemy_cms-3.2.1 lib/alchemy/touching.rb
lc_alchemy_cms-3.2.0 lib/alchemy/touching.rb
alchemy_cms-3.2.0 lib/alchemy/touching.rb
alchemy_cms-3.2.0.rc1 lib/alchemy/touching.rb
alchemy_cms-3.2.0.beta lib/alchemy/touching.rb
alchemy_cms-3.1.1 lib/alchemy/touching.rb
alchemy_cms-3.0.4 lib/alchemy/touching.rb
alchemy_cms-3.1.0 lib/alchemy/touching.rb
alchemy_cms-3.1.0.rc3 lib/alchemy/touching.rb
alchemy_cms-3.1.0.rc2 lib/alchemy/touching.rb
alchemy_cms-3.1.0.rc1 lib/alchemy/touching.rb
alchemy_cms-3.1.0.beta6 lib/alchemy/touching.rb
alchemy_cms-3.1.0.beta5 lib/alchemy/touching.rb
alchemy_cms-3.1.0.beta4 lib/alchemy/touching.rb
alchemy_cms-3.0.3 lib/alchemy/touching.rb
alchemy_cms-3.1.0.beta3 lib/alchemy/touching.rb
alchemy_cms-3.1.0.beta2 lib/alchemy/touching.rb
alchemy_cms-3.1.0.beta1 lib/alchemy/touching.rb