Module: Legion::Extensions::Builder::Hooks
- Includes:
- Base
- Included in:
- Core
- Defined in:
- lib/legion/extensions/builders/hooks.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Base
#const_defined_two?, #define_constant_two, #define_get, #find_files, #require_files
Instance Attribute Details
#hooks ⇒ Object
Returns the value of attribute hooks.
11
12
13
|
# File 'lib/legion/extensions/builders/hooks.rb', line 11
def hooks
@hooks
end
|
Instance Method Details
#build_hook_list ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/legion/extensions/builders/hooks.rb', line 21
def build_hook_list
hook_files.each do |file|
hook_name = file.split('/').last.sub('.rb', '')
hook_class_name = "#{lex_class}::Hooks::#{hook_name.split('_').collect(&:capitalize).join}"
next unless Kernel.const_defined?(hook_class_name)
hook_class = Kernel.const_get(hook_class_name)
next unless hook_class < Legion::Extensions::Hooks::Base
route_path = "#{extension_name}/#{hook_name}"
runner = resolve_hook_runner(hook_class)
@hooks[hook_name.to_sym] = {
extension: lex_class.to_s.downcase,
extension_name: extension_name,
hook_name: hook_name,
hook_class: hook_class,
route_path: route_path
}
next unless defined?(Legion::API) && Legion::API.respond_to?(:router)
hook_methods = hook_class.public_instance_methods(false).reject { |m| m.to_s.start_with?('_') }
hook_methods = [:handle] if hook_methods.empty?
hook_methods.each do |method_name|
Legion::API.router.register_extension_route(
lex_name: extension_name,
amqp_prefix: respond_to?(:amqp_prefix) ? amqp_prefix : "lex.#{extension_name.to_s.tr('_', '.')}",
component_type: 'hooks',
component_name: hook_name,
method_name: method_name.to_s,
runner_class: runner || hook_class,
definition: hook_class.respond_to?(:definition_for) ? hook_class.definition_for(method_name) : nil
)
end
end
end
|
#build_hooks ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/legion/extensions/builders/hooks.rb', line 13
def build_hooks
@hooks = {}
return unless Dir.exist? "#{extension_path}/hooks"
require_files(hook_files)
build_hook_list
end
|
#hook_files ⇒ Object
61
62
63
|
# File 'lib/legion/extensions/builders/hooks.rb', line 61
def hook_files
@hook_files ||= find_files('hooks')
end
|