Class: Pal::Main
Instance Attribute Summary collapse
Instance Method Summary
collapse
#config, #register_config
Methods included from Log
#log_debug, #log_error, #log_info, #log_warn
Methods included from Plugin
#register_plugins
Constructor Details
#initialize(config) ⇒ Main
Returns a new instance of Main.
21
22
23
|
# File 'lib/pal/main.rb', line 21
def initialize(config)
register_config(config)
end
|
Instance Attribute Details
18
19
20
|
# File 'lib/pal/main.rb', line 18
def manager
@manager
end
|
15
16
17
|
# File 'lib/pal/main.rb', line 15
def runbook
@runbook
end
|
Instance Method Details
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/pal/main.rb', line 40
def create_runbook(file_location)
file_relative = file_location.start_with?("/") ? file_location : File.join(File.dirname(__FILE__), file_location)
log_debug "Attempting to read file from [#{file_relative}]"
log_debug "Script executed from [#{__dir__}]"
request_content = File.read(file_relative)
Pal::Request::Runbook.new.from_json(request_content)
rescue JSON::ParserError => e
log_error("Malformed JSON request for file [#{file_location}]")
raise e, "Malformed JSON request for file [#{file_location}]"
end
|
54
55
56
57
58
59
60
61
|
# File 'lib/pal/main.rb', line 54
def create_service_manager
clazz_name = "Pal::Handler::#{@runbook.metadata.handler}HandlerImpl"
impl = Kernel.const_get(clazz_name).new(@runbook)
Pal::Handler::Manager.new(impl)
rescue NameError => e
log_error("Cannot find a valid handler impl for #{@runbook.metadata.handler}")
raise e
end
|
#process ⇒ Array, Hash
34
35
36
|
# File 'lib/pal/main.rb', line 34
def process
@manager.process_runbook(@runbook)
end
|
#setup ⇒ Object
26
27
28
29
30
31
|
# File 'lib/pal/main.rb', line 26
def setup
register_plugins
@runbook = create_runbook(config.template_file_loc)
@manager = create_service_manager
end
|