Class: CanTango::PermissionEngine::Collector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Debug

#debug

Constructor Details

#initialize(ability, permissions, type) ⇒ Collector

Returns a new instance of Collector.



8
9
10
11
12
13
# File 'lib/cantango/permission_engine/collector.rb', line 8

def initialize ability, permissions, type
  debug "Collecting #{type} permissions"
  @ability = ability
  @permissions = permissions
  @type = type
end

Instance Attribute Details

#abilityObject (readonly)

Returns the value of attribute ability.



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

def ability
  @ability
end

#permissionsObject (readonly)

Returns the value of attribute permissions.



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

def permissions
  @permissions
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#buildObject



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

def build
  relevant_rules.inject([]){|evaluators, (name, rules)|
    evaluators << CanTango::PermissionEngine::Evaluator.new(ability, rules) 
  }
end

#relevant_rulesObject



21
22
23
# File 'lib/cantango/permission_engine/collector.rb', line 21

def relevant_rules
  selector.select permissions
end

#role_groups_listObject



29
30
31
# File 'lib/cantango/permission_engine/collector.rb', line 29

def role_groups_list
  ability.role_groups
end

#roles_listObject



33
34
35
# File 'lib/cantango/permission_engine/collector.rb', line 33

def roles_list
  ability.roles
end

#selectorObject



25
26
27
# File 'lib/cantango/permission_engine/collector.rb', line 25

def selector
  CanTango::PermissionEngine::Selector.create type, self
end

#userObject



37
38
39
# File 'lib/cantango/permission_engine/collector.rb', line 37

def user
  ability.user
end

#user_accountObject Also known as: account



41
42
43
# File 'lib/cantango/permission_engine/collector.rb', line 41

def 
  ability.
end

#user_key_fieldObject



46
47
48
# File 'lib/cantango/permission_engine/collector.rb', line 46

def user_key_field
  ability.user_key_field
end