Sha256: 5d3807f2e85c177f0f369620f98e0d16e9bc50856cc431fabe35c4c34d60096f

Contents?: true

Size: 913 Bytes

Versions: 2

Compression:

Stored size: 913 Bytes

Contents

module Sinatra
  module PaperTrail

    # Register this module inside your Sinatra application to gain access to controller-level methods used by PaperTrail
    def self.registered(app)
      app.helpers Sinatra::PaperTrail
      app.before { set_paper_trail_whodunnit }
    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_paper_trail
      current_user if defined?(current_user)
    end

    private

    # Tells PaperTrail who is responsible for any changes that occur.
    def set_paper_trail_whodunnit
      ::PaperTrail.whodunnit = user_for_paper_trail if ::PaperTrail.enabled?
    end

  end

  register Sinatra::PaperTrail if defined?(register)
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
paper_trail_without_deprecated-3.0.0.beta1 lib/paper_trail/frameworks/sinatra.rb
paper_trail-3.0.0.beta1 lib/paper_trail/frameworks/sinatra.rb