Sha256: ec7a55843b3ef43a8eeb454241d013ef5f8776348b030281559acf232ca4e4b7

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 Bytes

Contents

module PaperTrail
  module Sinatra

    # Register this module inside your Sinatra application to gain access to controller-level methods used by PaperTrail
    def self.registered(app)
      app.helpers self
      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.try(:id) 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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
paper_trail-3.0.1 lib/paper_trail/frameworks/sinatra.rb