Sha256: dc9667a237f2d06409a079e329fde3684de4bcf2e9fc3ee66cdd42a34c35c62e

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require 'track_changes/filter'

module TrackChanges
  module ClassMethods
    # Uses a combination of <tt>before_filter</tt> and <tt>after_filter</tt>
    # to act on changes made to a module during a controllers <tt>update</tt>
    # action.
    #
    # Parameters:
    #
    # * <tt>model</tt>: A symbol of the model instance name to track changes to
    # * <tt>only_if_changed</tt>: If true, will only yield block if changes is not empty. Defaults to <tt>true</tt>.
    # * <tt>options</tt>: An options hash the will be supplied to <tt>before_filter</tt> and <tt>after_filter</tt>. Defaults to <tt>:only => :update</tt>.
    # * <tt>&block</tt>: The supplied block is called with an instance of Result as its parameter.
    def track_changes_to(models, only_if_changed = true, options = {:only => :update}, &block)
      append_before_filter(options) do |controller|
        track_filter = Filter.new(models, only_if_changed, block)
        controller.track_changes_filter = track_filter

        track_filter.before(controller)
      end

      append_after_filter(options)do |controller|
        controller.track_changes_filter.after(controller)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
smajn-track_changes-0.3.0 lib/track_changes/class_methods.rb
track_changes-0.3.2 lib/track_changes/class_methods.rb
track_changes-0.3.0 lib/track_changes/class_methods.rb