Module: Canable
- Defined in:
- lib/canable.rb
Defined Under Namespace
Modules: Ables, Cans, Enforcers
Classes: Transgression
Constant Summary
collapse
- Version =
'0.1.1'
Class Method Summary
collapse
Class Method Details
.actions ⇒ Object
Returns hash of actions that have been added.
{:view => :viewable, ...}
30
31
32
|
# File 'lib/canable.rb', line 30
def self.actions
@actions
end
|
.add(can, able) ⇒ Object
Adds an action to actions and the correct methods to can and able modules.
@param [Symbol] can_method The name of the can_[action]? method.
@param [Symbol] resource_method The name of the [resource_method]_by? method.
42
43
44
45
46
47
|
# File 'lib/canable.rb', line 42
def self.add(can, able)
@actions[can] = able
add_can_method(can, able)
add_able_method(able)
add_enforcer_method(can)
end
|
.add_able_method(able) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/canable.rb', line 59
def self.add_able_method(able)
Ables.module_eval " def \#{able}_by?(user)\n true\n end\n EOM\nend\n"
|
.add_can_method(can, able) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/canable.rb', line 50
def self.add_can_method(can, able)
Cans.module_eval " def can_\#{can}?(resource)\n return false if resource.blank?\n resource.\#{able}_by?(self)\n end\n EOM\nend\n"
|
.add_enforcer_method(can) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/canable.rb', line 67
def self.add_enforcer_method(can)
Enforcers.module_eval " def can_\#{can}?(resource)\n current_user.can_\#{can}?(resource)\n end\n\n def enforce_\#{can}_permission(resource)\n raise Canable::Transgression unless can_\#{can}?(resource)\n end\n private :enforce_\#{can}_permission\n EOM\nend\n"
|
.cans ⇒ Object
34
35
36
|
# File 'lib/canable.rb', line 34
def self.cans
actions.keys
end
|