Sha256: eec87a5eee7e3410208c817a20e73b3504bda2bbf49d9d3182d619742c092885

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

require 'active_support/core_ext/object' # provides the `try` method

module Draftsman
  module Sinatra

    # Register this module inside your Sinatra application to gain access to controller-level methods used by Draftsman
    def self.registered(app)
      app.helpers self
      app.before { set_draftsman_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_draftsman
      return unless defined?(current_user)
      ActiveSupport::VERSION::MAJOR >= 4 ? current_user.try!(:id) : current_user.try(:id)
    rescue NoMethodError
      current_user
    end

  private

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

  end

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
draftsman-0.7.2 lib/draftsman/frameworks/sinatra.rb
draftsman-0.7.1 lib/draftsman/frameworks/sinatra.rb
draftsman-0.7.0 lib/draftsman/frameworks/sinatra.rb
draftsman-0.6.0 lib/draftsman/frameworks/sinatra.rb
draftsman-0.5.1 lib/draftsman/frameworks/sinatra.rb
draftsman-0.5.0 lib/draftsman/frameworks/sinatra.rb
draftsman-0.4.0 lib/draftsman/frameworks/sinatra.rb
draftsman-0.3.7 lib/draftsman/frameworks/sinatra.rb
draftsman-0.3.6 lib/draftsman/frameworks/sinatra.rb
draftsman-0.3.5 lib/draftsman/frameworks/sinatra.rb
draftsman-0.3.4 lib/draftsman/frameworks/sinatra.rb
draftsman-0.3.3 lib/draftsman/frameworks/sinatra.rb
draftsman-0.3.2 lib/draftsman/frameworks/sinatra.rb