Module: Bcome::ContextFunctions
- Included in:
- Stack::Base
- Defined in:
- lib/context_functions.rb
Constant Summary collapse
- CONFIGS_PATH =
"bcome/config"
Instance Method Summary collapse
- #command_for_context(command) ⇒ Object
- #context_cmd_config_path ⇒ Object
- #context_cmd_functions ⇒ Object
- #context_commands ⇒ Object
- #execute_command_for_context(context_command) ⇒ Object
- #has_context_cmd_functions? ⇒ Boolean
- #has_context_functions_config? ⇒ Boolean
- #load_context_cmd_functions ⇒ Object
Instance Method Details
#command_for_context(command) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/context_functions.rb', line 10 def command_for_context(command) return false unless context_cmd_functions return false if !context_cmd_functions.any? ccfs = context_cmd_functions.select{|ccf| ccf[:command].to_s == command.to_s } raise "Multiple context commands found at context level #{} for command key #{command}" if ccfs.size > 1 return ccfs.first end |
#context_cmd_config_path ⇒ Object
48 49 50 |
# File 'lib/context_functions.rb', line 48 def context_cmd_config_path "#{CONFIGS_PATH}/context_functions.yml" end |
#context_cmd_functions ⇒ Object
34 35 36 37 |
# File 'lib/context_functions.rb', line 34 def context_cmd_functions return [] unless has_context_functions_config? @context_cmd_functions ||= load_context_cmd_functions end |
#context_commands ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/context_functions.rb', line 19 def context_commands if context_cmd_functions && context_cmd_functions.any? puts "\n\n\s\s" + "Context Commands". + "\n\n" context_cmd_functions.each_with_index do |context_function, index| puts "\n\t#{index+1}. #{context_function[:description].}" + "\n" puts "\tExecuted command:". + "\s#{context_function[:executed_command]} bcome_context=\"#{}\"" puts "\tUsage:". + "\s#{context_function[:command].command}" puts end else puts "You don't have any context specific functions defined yet." end return end |
#execute_command_for_context(context_command) ⇒ Object
5 6 7 8 |
# File 'lib/context_functions.rb', line 5 def execute_command_for_context(context_command) full_command = context_command[:executed_command] + " bcome_context=\"#{}\"" run_local(full_command) end |
#has_context_cmd_functions? ⇒ Boolean
39 40 41 |
# File 'lib/context_functions.rb', line 39 def has_context_cmd_functions? !context_cmd_functions.nil? end |
#has_context_functions_config? ⇒ Boolean
52 53 54 |
# File 'lib/context_functions.rb', line 52 def has_context_functions_config? File.exist?(context_cmd_config_path) end |
#load_context_cmd_functions ⇒ Object
43 44 45 46 |
# File 'lib/context_functions.rb', line 43 def load_context_cmd_functions configs = YAML.load_file(context_cmd_config_path) return configs[] end |