Sha256: 24e6bfa724968b673d9bebec73cc59c612ec9c1e327eb2bbec14ef1a533850c5

Contents?: true

Size: 1.07 KB

Versions: 9

Compression:

Stored size: 1.07 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 respond_to?(:contents)
      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 respond_to?(:touchable_pages)
      touchable_pages.update_all(touchable_attributes)
    end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
alchemy_cms-3.6.7 lib/alchemy/touching.rb
alchemy_cms-3.6.6 lib/alchemy/touching.rb
alchemy_cms-3.6.5 lib/alchemy/touching.rb
alchemy_cms-3.6.4 lib/alchemy/touching.rb
alchemy_cms-3.6.3 lib/alchemy/touching.rb
alchemy_cms-3.6.2 lib/alchemy/touching.rb
alchemy_cms-3.6.1 lib/alchemy/touching.rb
alchemy_cms-4.0.0.beta lib/alchemy/touching.rb
alchemy_cms-3.6.0 lib/alchemy/touching.rb