Module: Middle
- Extended by:
- ActiveSupport::Concern
- Included in:
- Ability
- Defined in:
- lib/middle.rb,
lib/middle/rule.rb,
lib/middle/rails.rb,
lib/middle/version.rb,
lib/generators/middle/ability/ability_generator.rb,
lib/generators/middle/install/install_generator.rb
Defined Under Namespace
Modules: ClassMethods, Generators, Rails
Classes: Rule
Constant Summary
collapse
- VERSION =
'0.1.0'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
95
96
97
|
# File 'lib/middle.rb', line 95
def current_user
@current_user
end
|
Instance Method Details
#can?(action, subject, options = {}) ⇒ Boolean
105
106
107
108
109
110
|
# File 'lib/middle.rb', line 105
def can?(action, subject, options = {})
name = build_name_for(action, subject)
rule = rules[name] || rules["#{action}_all"]
return false unless rule
rule.result(subject, options)
end
|
#cannot?(*args) ⇒ Boolean
112
113
114
|
# File 'lib/middle.rb', line 112
def cannot?(*args)
!can?(*args)
end
|
#initialize(user) ⇒ Object
97
98
99
|
# File 'lib/middle.rb', line 97
def initialize(user)
@current_user = self.class.current_user = user
end
|
#rules ⇒ Object
101
102
103
|
# File 'lib/middle.rb', line 101
def rules
@rules ||= self.class.rules
end
|