Class: Ez::Resources::Manager::Hooks
- Inherits:
-
Object
- Object
- Ez::Resources::Manager::Hooks
- Defined in:
- lib/ez/resources/manager/hooks.rb
Instance Attribute Summary collapse
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
Class Method Summary collapse
Instance Method Summary collapse
- #add(name, callback) ⇒ Object
-
#initialize(&block) ⇒ Hooks
constructor
A new instance of Hooks.
Constructor Details
#initialize(&block) ⇒ Hooks
Returns a new instance of Hooks.
26 27 28 29 30 |
# File 'lib/ez/resources/manager/hooks.rb', line 26 def initialize(&block) @hooks = [] instance_eval(&block) end |
Instance Attribute Details
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
9 10 11 |
# File 'lib/ez/resources/manager/hooks.rb', line 9 def hooks @hooks end |
Class Method Details
.can!(name, config, data = nil) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/ez/resources/manager/hooks.rb', line 11 def self.can!(name, config, data = nil) return true if config.hooks.empty? if config.hooks.select { |h| h.name == name }.map { |h| h.callback.call(config.controller, data) }.all?(true) return true end raise UnavailableError, "Negative #{name}" end |
.can?(name, config, data = nil) ⇒ Boolean
20 21 22 23 24 |
# File 'lib/ez/resources/manager/hooks.rb', line 20 def self.can?(name, config, data = nil) return true if config.hooks.empty? config.hooks.select { |h| h.name == name }.map { |h| h.callback.call(config.controller, data) }.all?(true) end |