Module: Kan::Abilities
- Defined in:
- lib/kan/abilities.rb
Defined Under Namespace
Modules: ClassMethods
Classes: InvalidAbilityNameError, InvalidRoleObjectError
Constant Summary
collapse
- DEFAULT_ABILITY_BLOCK =
proc { true }
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
58
59
60
|
# File 'lib/kan/abilities.rb', line 58
def logger
@logger
end
|
Class Method Details
.included(base) ⇒ Object
5
6
7
|
# File 'lib/kan/abilities.rb', line 5
def self.included(base)
base.extend(ClassMethods)
end
|
Instance Method Details
#ability(name) ⇒ Object
65
66
67
68
|
# File 'lib/kan/abilities.rb', line 65
def ability(name)
rule = self.class.ability_list[name.to_sym] || @options[:default_ability_block] || DEFAULT_ABILITY_BLOCK
->(*args) { instance_exec(args, &rule) }
end
|
#initialize(options = {}) ⇒ Object
60
61
62
63
|
# File 'lib/kan/abilities.rb', line 60
def initialize(options = {})
@options = options
@logger = @options.fetch(:logger, Logger.new(STDOUT))
end
|