Class: CanTango::PermissionEngine::Factory

Inherits:
Object
  • Object
show all
Includes:
Helpers::Debug
Defined in:
lib/cantango/permission_engine/factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Debug

#debug

Constructor Details

#initialize(ability) ⇒ Factory

creates the factory for the ability note that the ability contains the roles and role groups of the user (or account)

Parameters:

  • the (Permits::Ability)

    ability



11
12
13
# File 'lib/cantango/permission_engine/factory.rb', line 11

def initialize ability
  @ability = ability
end

Instance Attribute Details

#abilityObject

Returns the value of attribute ability.



6
7
8
# File 'lib/cantango/permission_engine/factory.rb', line 6

def ability
  @ability
end

Instance Method Details

#build!Object



15
16
17
18
19
20
21
# File 'lib/cantango/permission_engine/factory.rb', line 15

def build!
  debug "building permissions"
  @evaluators ||= permission_types.inject([]) do |res, type|
    res << collector(type).build
    res
  end.flatten.compact
end

#collector(type) ⇒ Object



23
24
25
26
# File 'lib/cantango/permission_engine/factory.rb', line 23

def collector(type)
  rules = store.send(:"#{type}_rules")
  CanTango::PermissionEngine::Collector.new(ability, rules, type)
end

#config_pathObject



48
49
50
# File 'lib/cantango/permission_engine/factory.rb', line 48

def config_path
  permission_engine.config_path
end

#optionsObject



28
29
30
# File 'lib/cantango/permission_engine/factory.rb', line 28

def options
  ability.options
end

#permission_typesObject



44
45
46
# File 'lib/cantango/permission_engine/factory.rb', line 44

def permission_types
  permission_engine.types
end

#storeObject



32
33
34
# File 'lib/cantango/permission_engine/factory.rb', line 32

def store
  store_class.new :permissions, store_options
end

#store_classObject



36
37
38
# File 'lib/cantango/permission_engine/factory.rb', line 36

def store_class
  permission_engine.store.default_class
end

#store_optionsObject



40
41
42
# File 'lib/cantango/permission_engine/factory.rb', line 40

def store_options
  permission_engine.store.options.merge(:path => config_path)
end