module SimpleCan

Constants

THREAD_VAR

Attributes

strategy[RW]

Public Class Methods

included(mod) click to toggle source
# File lib/simple_can.rb, line 10
def self.included(mod)
  strategy_set!
  meta = class << mod; self; end
  meta.send(:alias_method, :orig_method_added, :method_added)
  meta.send(:alias_method, :orig_singleton_method_added,
    :singleton_method_added)
  mod.extend(ClassMethods)

  strategy.roles.each do |role|
    [meta, mod].each do |scope|
      scope.send(:define_method, "#{role}?") do
        mod.strategy_set!
        SimpleCan.strategy.test(role, mod.capability)
      end
      scope.send(:define_method, "#{role}!") do
        mod.strategy_set!
        next if SimpleCan.strategy.test(role, mod.capability)
        raise SimpleCan::Unauthorized, "unauthorized with #{role}"
      end
    end
  end
end
strategy_set!() click to toggle source
# File lib/simple_can.rb, line 33
def self.strategy_set!
  raise "strategy missing" if SimpleCan.strategy.nil?
end