Sha256: cd5da49da15691bcb18872dcdd019b9cb804984f85d047b7a345ed7e147a80ef

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

# encoding: UTF-8

module Spontaneous::Model::Page
  # Various scenarios where we need to Update the Site's modification
  # time to force clients to reload their map data
  module SiteTimestamps
    extend Spontaneous::Concern

    def before_save_field(field)
      mark_site_modified if ((field.name == title_field) && field.modified?)
      super
    end

    # The UI map uses the slugs for the pulldown values so changes to the
    # slug must force a reload or things get very odd.
    def before_update
      mark_site_modified if changed_columns.include?(:slug)
      super
    end

    def after_update
      mark_site_modified if field?(title_field) && fields[title_field].modified?
      super
    end

    def after_create
      mark_site_modified
      super
    end

    # Update the Site's modification time to force clients
    # to reload their map data
    def after_destroy
      mark_site_modified
      super
    end

    protected

    def mark_site_modified
      ::Spontaneous::State.site_modified!
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta5 lib/spontaneous/model/page/site_timestamps.rb
spontaneous-0.2.0.beta4 lib/spontaneous/model/page/site_timestamps.rb
spontaneous-0.2.0.beta3 lib/spontaneous/model/page/site_timestamps.rb
spontaneous-0.2.0.beta2 lib/spontaneous/model/page/site_timestamps.rb
spontaneous-0.2.0.beta1 lib/spontaneous/model/page/site_timestamps.rb