Class: MoulinRouge::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/moulin_rouge/authorization.rb

Overview

An sinlgeton inherited instace of this class acts like a proxy to main ability evaluating all methods in its scope to proper later evaluation

Class Method Summary collapse

Class Method Details

.abilitiesObject

Returns an hash with all permissions defined



26
27
28
# File 'lib/moulin_rouge/authorization.rb', line 26

def abilities
  @@abilities ||= {}
end

.compile!Object

Load and initialize all authorization files in the configuration path



38
39
40
# File 'lib/moulin_rouge/authorization.rb', line 38

def compile!
  Dir[MoulinRouge.configuration.path].each { |file| Kernel.load(file) }
end

.mainObject

The instance of the main ability



16
17
18
# File 'lib/moulin_rouge/authorization.rb', line 16

def main
  @@main ||= MoulinRouge::Ability.new(:main)
end

.method_missing(name, *args, &block) ⇒ Object

Delegates the missing method for the main ability



11
12
13
# File 'lib/moulin_rouge/authorization.rb', line 11

def method_missing(name, *args, &block)
  main.send(name, *args, &block)
end

.register(instance) ⇒ Object

Register an ability in the singleton



31
32
33
34
35
# File 'lib/moulin_rouge/authorization.rb', line 31

def register(instance)
  name = instance.name
  self.abilities[name] = instance
  self.roles << name unless self.roles.include?(name)
end

.reset!Object

Reset all constants



43
44
45
# File 'lib/moulin_rouge/authorization.rb', line 43

def reset! #:nodoc:
  @@main, @@roles, @@abilities = nil
end

.rolesObject

Returns an array with the name of all roles created



21
22
23
# File 'lib/moulin_rouge/authorization.rb', line 21

def roles
  @@roles ||= []
end