Module: Governor

Defined in:
lib/governor.rb,
lib/governor/rails.rb,
lib/governor/plugin.rb,
lib/governor/article.rb,
lib/governor/mapping.rb,
lib/governor/formatters.rb,
lib/governor/view_manager.rb,
lib/governor/plugin_manager.rb,
lib/governor/controllers/helpers.rb,
lib/governor/controllers/methods.rb,
lib/generators/governor/migrate_generator.rb,
lib/generators/governor/configure_generator.rb,
lib/generators/governor/create_articles_generator.rb

Defined Under Namespace

Modules: Article, Controllers, Formatters Classes: ConfigureGenerator, CreateArticlesGenerator, Engine, Mapping, MigrateGenerator, Plugin, PluginManager, ViewManager

Constant Summary collapse

@@resources =
{}

Class Method Summary collapse

Class Method Details

.authorize_if(&blk) ⇒ Object

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


95
96
97
# File 'lib/governor.rb', line 95

def self.authorize_if(&blk)
  @@authorization_rules = blk
end

.map(resource, options = {}) ⇒ Object

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



70
71
72
# File 'lib/governor.rb', line 70

def self.map(resource, options = {})
  @@default_resource ||= self.resources[resource] = Governor::Mapping.new(resource, options)
end