Sha256: 746d46ec75f26ce03c12626b5bd18c374c4674139d57aba620ee7af1961f04a0

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

module Draftsman
  module Rails
    module Controller

      def self.included(base)
        base.before_filter :set_draftsman_whodunnit, :set_draftsman_controller_info
      end

    protected

      # Returns the user who is responsible for any changes that occur.
      # By default this calls `current_user` and returns the result.
      #
      # Override this method in your controller to call a different
      # method, e.g. `current_person`, or anything you like.
      def user_for_draftsman
        current_user if defined?(current_user)
      end

      # Returns any information about the controller or request that you
      # want Draftsman to store alongside any changes that occur.  By
      # default, this returns an empty hash.
      #
      # Override this method in your controller to return a hash of any
      # information you need. The hash's keys must correspond to columns
      # in your `drafts` table, so don't forget to add any new columns
      # you need.
      #
      # For example:
      #
      #     {:ip => request.remote_ip, :user_agent => request.user_agent}
      #
      # The columns `ip` and `user_agent` must exist in your `drafts` # table.
      #
      # Use the `:meta` option to `Draftsman::Model::ClassMethods.has_drafts`
      # to store any extra model-level data you need.
      def info_for_draftsman
        {}
      end

    private

      # Tells Draftsman who is responsible for any changes that occur.
      def set_draftsman_whodunnit
        ::Draftsman.whodunnit = user_for_draftsman
      end

      # Tells Draftsman any information from the controller you want
      # to store alongside any changes that occur.
      def set_draftsman_controller_info
        ::Draftsman.controller_info = info_for_draftsman
      end

    end
  end

  if defined?(::ActionController)
    ::ActiveSupport.on_load(:action_controller) { include Draftsman::Rails::Controller }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
draftsman-0.4.0 lib/draftsman/frameworks/rails.rb
draftsman-0.3.7 lib/draftsman/frameworks/rails.rb
draftsman-0.3.6 lib/draftsman/frameworks/rails.rb