Class: CanTango::Configuration::Permits

Inherits:
PermitRegistry show all
Includes:
Singleton
Defined in:
lib/cantango/configuration/permits.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



16
17
18
# File 'lib/cantango/configuration/permits.rb', line 16

def method_missing method_name, *args
  accounts[method_name] ||= PermitRegistry.new
end

Instance Attribute Details

#accountsObject (readonly)

Returns the value of attribute accounts.



6
7
8
# File 'lib/cantango/configuration/permits.rb', line 6

def accounts
  @accounts
end

Instance Method Details

#account_hash(name) ⇒ Object



12
13
14
# File 'lib/cantango/configuration/permits.rb', line 12

def  name
  accounts[name]
end

#allowed(candidate, actions, subjects, *extra_args) ⇒ Object



25
26
27
28
29
30
# File 'lib/cantango/configuration/permits.rb', line 25

def allowed candidate, actions, subjects, *extra_args
  executed_for(candidate).inject([]) do |result, permit|
    result << permit.class if permit.can? actions, subjects, *extra_args
    result
  end
end

#clear_executed!Object



51
52
53
# File 'lib/cantango/configuration/permits.rb', line 51

def clear_executed!
  @executed = nil
end

#denied(candidate, actions, subjects, *extra_args) ⇒ Object



32
33
34
35
36
37
# File 'lib/cantango/configuration/permits.rb', line 32

def denied candidate, actions, subjects, *extra_args
  executed_for(candidate).inject([]) do |result, permit|
    result << permit.class if permit.cannot? actions, subjects, *extra_args
    result
  end
end

#executedObject



47
48
49
# File 'lib/cantango/configuration/permits.rb', line 47

def executed
  @executed ||= {}
end

#executed_for(ability) ⇒ Object



43
44
45
# File 'lib/cantango/configuration/permits.rb', line 43

def executed_for ability
  executed[hash_key_for(ability)] ||= []
end

#register_permit_class(permit_name, permit_clazz, permit_type, account_name) ⇒ Object



20
21
22
23
# File 'lib/cantango/configuration/permits.rb', line 20

def register_permit_class(permit_name, permit_clazz, permit_type, )
  registry =  ? self.send(.to_sym) : self
  registry.send(permit_type)[permit_name] = permit_clazz
end

#was_executed(permit, ability) ⇒ Object



39
40
41
# File 'lib/cantango/configuration/permits.rb', line 39

def was_executed permit, ability
  executed_for(ability) << permit
end