Class: Bcome::Registry::Command::External
- Inherits:
-
Base
- Object
- Base
- Bcome::Registry::Command::External
show all
- Defined in:
- lib/objects/registry/command/external.rb
Instance Method Summary
collapse
Methods inherited from Base
#defaults, #initialize, is_valid_type?, #method_missing, new_from_raw_command, #process_arguments, valid_types, #validate, #validation_error
Instance Method Details
#construct_full_command(node, arguments) ⇒ Object
15
16
17
18
19
|
# File 'lib/objects/registry/command/external.rb', line 15
def construct_full_command(node, arguments)
substituted_command = construct_substituted_command(arguments)
namespaced_command = namespace_command(node, substituted_command)
namespaced_command
end
|
#construct_substituted_command(arguments) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/objects/registry/command/external.rb', line 21
def construct_substituted_command(arguments)
substituted_command = local_command.dup
merged_arguments = process_arguments(arguments)
local_command_substitutions.each do |substitution|
substitute_with = merged_arguments[substitution.to_sym]
if substitute_with.nil?
error_message_suffix = "- missing '#{substitution}' from command '#{local_command}'"
raise Bcome::Exception::MissingArgumentForRegistryCommand, error_message_suffix
end
substitute_with = [TrueClass, FalseClass].include?(substitute_with.class) ? (substitute_with ? "true" : "false") : substitute_with
substituted_command.gsub!("%#{substitution}%", substitute_with)
end
substituted_command
end
|
#do_pretty_print ⇒ Object
50
51
52
53
54
|
# File 'lib/objects/registry/command/external.rb', line 50
def do_pretty_print
= super + "\n\s\s\s\slocal command:\s".resource_key + local_command.resource_value
+= "\n\s\s\s\sdefaults:\s".resource_key + defaults.inspect.resource_value
+ "\n\n"
end
|
#execute(node, arguments) ⇒ Object
In which the bcome context is passed to an external call
5
6
7
8
9
10
11
12
13
|
# File 'lib/objects/registry/command/external.rb', line 5
def execute(node, arguments)
full_command = construct_full_command(node, arguments)
begin
puts "\n(external) > #{full_command}".bc_blue + "\n\n"
system(full_command)
rescue Interrupt
puts "\nExiting gracefully from interrupt\n".warning
end
end
|
#expected_keys ⇒ Object
46
47
48
|
# File 'lib/objects/registry/command/external.rb', line 46
def expected_keys
super + [:local_command]
end
|
#local_command_substitutions ⇒ Object
42
43
44
|
# File 'lib/objects/registry/command/external.rb', line 42
def local_command_substitutions
local_command.scan(/%([^%]*)%/).flatten.uniq
end
|
#namespace_command(node, command) ⇒ Object
38
39
40
|
# File 'lib/objects/registry/command/external.rb', line 38
def namespace_command(node, command)
"#{command} bcome_context=\"#{node.keyed_namespace}\""
end
|