module Governor

Public Class Methods

authorize_if(&blk) click to toggle source

Supply a set of rules that describe what the requirements are to perform a given Governor-related action on a given article. Usually specified within the initializer, though evaluated in the scope of a Rails session.

Example (from the generated initialization file):

Governor.authorize_if do |action, article|
  case action.to_sym
  when :new, :create
    if respond_to?(:user_signed_in?)
      user_signed_in?
    else
      raise "Set up Governor.authorize_if in #{File.expand_path(__FILE__)}"
    end
  when :edit, :update, :destroy
    article.author == instance_eval(&Governor.author)
  else
    raise ArgumentError.new('action must be new, create, edit, update, or destroy')
  end
end
# File lib/governor.rb, line 95
def self.authorize_if(&blk)
  @@authorization_rules = blk
end
map(resource, options = {}) click to toggle source

Maps a given resource name with a pair of options, to be supplied as arguments to the routes. Usually called from within governate.

# File lib/governor.rb, line 70
def self.map(resource, options = {})
  @@default_resource ||= self.resources[resource] = Governor::Mapping.new(resource, options)
end