module Draftsman::Sinatra

Public Class Methods

registered(app) click to toggle source

Register this module inside your Sinatra application to gain access to controller-level methods used by Draftsman

# File lib/draftsman/frameworks/sinatra.rb, line 7
def self.registered(app)
  app.helpers self
  app.before { set_draftsman_whodunnit }
end

Protected Instance Methods

user_for_draftsman() click to toggle source

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.

# File lib/draftsman/frameworks/sinatra.rb, line 19
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 Instance Methods

set_draftsman_whodunnit() click to toggle source

Tells Draftsman who is responsible for any changes that occur.

# File lib/draftsman/frameworks/sinatra.rb, line 29
def set_draftsman_whodunnit
  ::Draftsman.whodunnit = user_for_draftsman if ::Draftsman.enabled?
end