Class: MiniDeploy::ReceiptReader
- Inherits:
-
Object
- Object
- MiniDeploy::ReceiptReader
show all
- Includes:
- ReceiptFormatter
- Defined in:
- lib/mini_deploy/receipt_reader.rb
Instance Method Summary
collapse
#format_check_or_remove_file_task, #format_default_task_value, #format_find_file_content_task, #format_send_http_request_task, #format_upload_file_task
Constructor Details
#initialize(receipt_file_path) ⇒ ReceiptReader
Returns a new instance of ReceiptReader.
8
9
10
11
12
|
# File 'lib/mini_deploy/receipt_reader.rb', line 8
def initialize(receipt_file_path)
@receipt_file_path = receipt_file_path
@receipt = nil
end
|
Instance Method Details
#fetch ⇒ Object
14
15
16
|
# File 'lib/mini_deploy/receipt_reader.rb', line 14
def fetch
format(read_receipt)
end
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/mini_deploy/receipt_reader.rb', line 18
def format(receipt_data)
new_data = {
is_valid: false,
deploy_nodes: receipt_data.fetch('deploy_nodes'),
receipt_title: receipt_data.fetch('title') { 'Untitled Receipt' },
receipt_create_at: receipt_data.fetch('date') { 'No Data' },
receipt_author: receipt_data.fetch('author') { 'No Author Name '},
receipt_tasks: nil,
agent_name: receipt_data.fetch('agent_name') { "MiniDeploy/#{MiniDeploy::VERSION}" },
time: Time.now.utc
}
new_data[:receipt_tasks] = format_tasks(receipt_data['tasks'])
new_data
rescue StandardError
raise ReceiptReaderParseError
end
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/mini_deploy/receipt_reader.rb', line 47
def format_task(old_task)
new_task = format_default_task_value(old_task)
new_option = nil
case new_task[:process]
when :check_file
new_option = format_check_or_remove_file_task(old_task)
when :send_http_request
new_option = format_send_http_request_task(old_task)
when :remove_file
new_option = format_check_or_remove_file_task(old_task)
when :upload_file
new_option = format_upload_file_task(old_task)
when :find_file_content
new_option = format_find_file_content_task(old_task)
else
new_option = nil
end
if new_option.is_a?(Hash)
new_task.merge(new_option)
else
nil
end
end
|
37
38
39
40
41
42
43
44
45
|
# File 'lib/mini_deploy/receipt_reader.rb', line 37
def format_tasks(tasks_data)
[] unless tasks_data.is_a?(Array)
tasks_data.map! do |task|
format_task(task)
end
tasks_data.compact
end
|
#read_receipt ⇒ Object
73
74
75
76
77
|
# File 'lib/mini_deploy/receipt_reader.rb', line 73
def read_receipt
YAML.load(IO.read(@receipt_file_path))
rescue StandardError
raise ReceiptReaderLoadError
end
|