Class: Bcome::Stack::Base
- Includes:
- CommandHelper, ContextFunctions
- Defined in:
- lib/stack/base.rb
Direct Known Subclasses
Constant Summary
Constants included from ContextFunctions
ContextFunctions::CONFIGS_PATH
Instance Method Summary collapse
- #available_resources_options_string ⇒ Object
- #become(object) ⇒ Object
-
#become_identifier ⇒ Object
Core workspace behaviour.
- #construct_node ⇒ Object
- #describe ⇒ Object
- #highlight? ⇒ Boolean
- #init ⇒ Object
- #machines ⇒ Object
- #menu ⇒ Object
- #menu_items ⇒ Object
- #method_missing(method_sym, *arguments, &block) ⇒ Object
-
#node ⇒ Object
Construction & Initialisation.
- #node_level_klass ⇒ Object
- #recipes ⇒ Object
- #workon(identifier) ⇒ Object (also: #w, #cd)
Methods included from CommandHelper
Methods included from ContextFunctions
#command_for_context, #context_cmd_config_path, #context_cmd_functions, #context_commands, #execute_command_for_context, #has_context_cmd_functions?, #has_context_functions_config?, #load_context_cmd_functions
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/stack/base.rb', line 23 def method_missing(method_sym, *arguments, &block) if command_for_context = command_for_context(method_sym) execute_command_for_context(command_for_context) elsif recipe = ::Bcome::Orchestrator::Recipe.by_identifier(method_sym.to_s, self) puts "Executing Command Recipe #{recipe.recipe_identifier}".informational puts "Description: #{recipe.description}".command recipe.execute!(machines) return else super end end |
Instance Method Details
#available_resources_options_string ⇒ Object
105 106 107 |
# File 'lib/stack/base.rb', line 105 def "Please select from one of: #{all_items.join(', ')}'" end |
#become(object) ⇒ Object
66 67 68 |
# File 'lib/stack/base.rb', line 66 def become(object) BECOME.set(object, self) end |
#become_identifier ⇒ Object
Core workspace behaviour
62 63 64 |
# File 'lib/stack/base.rb', line 62 def become_identifier ::START_PROMPT end |
#construct_node ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/stack/base.rb', line 36 def construct_node node_attributes = node_attributes.merge!({ collection_key => resources.collect(&:node) }) if respond_to?(:collection_key) this_node = node_level_klass.new(node_attributes) this_node.set_parent_reference(this_node, child_reference_key, collection_key) if respond_to?(:collection_key) && respond_to?(:child_reference_key) return this_node end |
#describe ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/stack/base.rb', line 109 def describe if self.respond_to?(:do_describe) = "\n\tCollection Key:". + "\s#{reference_key}\n\n#{self.do_describe}" else = "\nNothing to describe. Use 'ls' or 'list' to see namespace options".headsup unless self.respond_to?(:do_describe) end puts end |
#highlight? ⇒ Boolean
101 102 103 |
# File 'lib/stack/base.rb', line 101 def highlight? false ## override in stack objects that should be highlighted within a list, e.g. instance objects at the environment level that have been selected to workon on end |
#init ⇒ Object
53 54 55 56 |
# File 'lib/stack/base.rb', line 53 def init puts "loading resources #{self.class} " node end |
#machines ⇒ Object
7 8 9 |
# File 'lib/stack/base.rb', line 7 def machines node.machines end |
#menu ⇒ Object
84 85 86 |
# File 'lib/stack/base.rb', line 84 def ::RENDER.(, self) end |
#menu_items ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/stack/base.rb', line 88 def [ { :command => "list / ls", :description => "List all available resources at the current context." }, { :command => "describe", :description => "Describe the resource object at the current context." }, { :command => "cd [Node Name]", :description => "Select a resource object, and switch to its context.", :usage => "cd 'YourServerName'" }, { :command => "exit", :description => "Return to the previous context" }, { :command => "exit!", :description => "Close all contexts, and exit Become."}, { :command => "local", :description => "Execute a shell command on your local machine.", :usage => 'local "command"'}, { :command => "machines", :description => "Return all servers below the current level to the console. These objects can be manipulated directly" }, { :command => "context_commands", :description => "List all shell commands for invoking non-shell processes, in the current bcome context" }, ] end |
#node ⇒ Object
Construction & Initialisation
15 16 17 |
# File 'lib/stack/base.rb', line 15 def node @node ||= construct_node end |
#node_level_klass ⇒ Object
49 50 51 |
# File 'lib/stack/base.rb', line 49 def node_level_klass raise "Should be overidden in derived stack type" end |
#recipes ⇒ Object
19 20 21 |
# File 'lib/stack/base.rb', line 19 def recipes [] end |
#workon(identifier) ⇒ Object Also known as: w, cd
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/stack/base.rb', line 70 def workon(identifier) resource = resource_for_identifier(identifier) unless resource puts "\nNo matching #{collection_key} for identifier '#{identifier}'.".failure + "\n\n#{}" + "\n\n" else puts "\nFrom #{resource.reference_key}, working on '#{identifier}'.".informational + "\n\n" puts "Hit 'menu' or 'ls' to see what you can do here.\n\n" become(resource) end end |