Class: R2OAS::Hooks::Hook
- Includes:
- Singleton
- Defined in:
- lib/r2-oas/hooks/hook.rb
Class Attribute Summary collapse
-
.repository ⇒ Object
Returns the value of attribute repository.
Class Method Summary collapse
- .execute_hook(on, *data, target_class) ⇒ Object
- .has_hook?(name, target_class) ⇒ Boolean
-
.off(uid, target_class) ⇒ Object
MEMO: Do not Use.
- .on(on, callback, target_class, once = false) ⇒ Object
- .register(type, target_class) ⇒ Object
Class Attribute Details
.repository ⇒ Object
Returns the value of attribute repository.
13 14 15 |
# File 'lib/r2-oas/hooks/hook.rb', line 13 def repository @repository end |
Class Method Details
.execute_hook(on, *data, target_class) ⇒ Object
56 57 58 59 60 |
# File 'lib/r2-oas/hooks/hook.rb', line 56 def execute_hook(on, *data, target_class) return data unless has_hook?(on, target_class) execute_global_hook(on, *data, target_class) end |
.has_hook?(name, target_class) ⇒ Boolean
62 63 64 |
# File 'lib/r2-oas/hooks/hook.rb', line 62 def has_hook?(name, target_class) !!get_hook(name, target_class) end |
.off(uid, target_class) ⇒ Object
MEMO: Do not Use
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/r2-oas/hooks/hook.rb', line 38 def off(uid, target_class) target_repository = @repository[@type][target_class] result = uid target_repository.global_hooks_data.each do |on| global_hooks = target_repository.global_hooks_data[on] index = global_hooks.find_index { |hook| hook.uid == uid } if index global_hooks.delete_if { |hook| hook.uid == uid } else result = nil end end result end |
.on(on, callback, target_class, once = false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/r2-oas/hooks/hook.rb', line 24 def on(on, callback, target_class, once = false) target_repository = @repository[@type][target_class] uid = target_repository.last_hook_id + 1 target_repository.last_hook_id = uid target_repository.global_hooks_data[on] ||= [] global_hook = GlobalHook.new(callback, once, uid, target_class) target_repository.global_hooks_data[on].push(global_hook) uid end |
.register(type, target_class) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/r2-oas/hooks/hook.rb', line 15 def register(type, target_class) @repository ||= {} @repository[type] ||= {} @type = type @hooks ||= {} @repository[type][target_class] = Repository.new(target_class) self end |