Module: Bcome::WorkspaceCommands
- Included in:
- Node::Base
- Defined in:
- lib/objects/modules/workspace_commands.rb
Instance Method Summary collapse
- #cd(identifier) ⇒ Object
- #clear! ⇒ Object
- #disable(*ids) ⇒ Object
- #disable! ⇒ Object
- #enable(*ids) ⇒ Object
- #enable! ⇒ Object
- #interactive ⇒ Object
- #is_node_level_method?(method_sym) ⇒ Boolean
- #ls(node = self, active_only = false) ⇒ Object
- #lsa ⇒ Object
- #method_in_registry?(method_sym) ⇒ Boolean
- #method_is_available_on_node?(method_sym) ⇒ Boolean
- #new_line ⇒ Object
- #parents ⇒ Object
- #ping ⇒ Object
- #pretty_description(is_active = true) ⇒ Object
-
#resource_identifiers ⇒ Object
Helpers –.
- #run(*raw_commands) ⇒ Object
- #ssh_connect(params = {}) ⇒ Object
- #tree_descriptions ⇒ Object
- #visual_hierarchy ⇒ Object
- #workon(*ids) ⇒ Object
Instance Method Details
#cd(identifier) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/objects/modules/workspace_commands.rb', line 52 def cd(identifier) if (resource = resources.for_identifier(identifier)) if resource.parent.resources.is_active_resource?(resource) ::Bcome::Workspace.instance.set(current_context: self, context: resource) else puts "\nCannot enter context - #{identifier} is disabled. To enable enter 'enable #{identifier}'\n".error end else raise Bcome::Exception::InvalidBreadcrumb, "Cannot find a node named '#{identifier}'" puts "#{identifier} not found" end end |
#clear! ⇒ Object
109 110 111 112 113 114 |
# File 'lib/objects/modules/workspace_commands.rb', line 109 def clear! # Clear any disabled selection at this level and at all levels below resources.clear! resources.each(&:clear!) nil end |
#disable(*ids) ⇒ Object
101 102 103 |
# File 'lib/objects/modules/workspace_commands.rb', line 101 def disable(*ids) ids.each { |id| resources.do_disable(id) } end |
#disable! ⇒ Object
122 123 124 125 126 |
# File 'lib/objects/modules/workspace_commands.rb', line 122 def disable! resources.disable! resources.each(&:disable!) nil end |
#enable(*ids) ⇒ Object
105 106 107 |
# File 'lib/objects/modules/workspace_commands.rb', line 105 def enable(*ids) ids.each { |id| resources.do_enable(id) } end |
#enable! ⇒ Object
128 129 130 131 132 |
# File 'lib/objects/modules/workspace_commands.rb', line 128 def enable! resources.enable! resources.each(&:enable!) nil end |
#interactive ⇒ Object
42 43 44 |
# File 'lib/objects/modules/workspace_commands.rb', line 42 def interactive ::Bcome::Interactive::Session.run(self, :interactive_ssh) end |
#is_node_level_method?(method_sym) ⇒ Boolean
140 141 142 |
# File 'lib/objects/modules/workspace_commands.rb', line 140 def is_node_level_method?(method_sym) respond_to?(method_sym) || method_is_available_on_node?(method_sym) end |
#ls(node = self, active_only = false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/objects/modules/workspace_commands.rb', line 9 def ls(node = self, active_only = false) if node != self && (resource = resources.for_identifier(node)) resource.send(:ls, active_only) else puts "\n\n" + visual_hierarchy.hierarchy + "\n" puts "\t" + "Available #{list_key}s:" + "\n\n" iterate_over = active_only ? resources.active : resources if iterate_over.any? iterate_over.sort_by(&:identifier).each do |resource| next if resource.hide? is_active = resources.is_active_resource?(resource) puts resource.pretty_description(is_active) puts "\n" end else puts "\tNo resources found".informational end new_line nil end end |
#lsa ⇒ Object
37 38 39 40 |
# File 'lib/objects/modules/workspace_commands.rb', line 37 def lsa show_active_only = true ls(self, show_active_only) end |
#method_in_registry?(method_sym) ⇒ Boolean
144 145 146 |
# File 'lib/objects/modules/workspace_commands.rb', line 144 def method_in_registry?(method_sym) ::Bcome::Registry::CommandList.instance.command_in_list?(self, method_sym) end |
#method_is_available_on_node?(method_sym) ⇒ Boolean
148 149 150 |
# File 'lib/objects/modules/workspace_commands.rb', line 148 def method_is_available_on_node?(method_sym) resource_identifiers.include?(method_sym.to_s) || method_in_registry?(method_sym) || respond_to?(method_sym) || instance_variable_defined?("@#{method_sym}") end |
#new_line ⇒ Object
167 168 169 |
# File 'lib/objects/modules/workspace_commands.rb', line 167 def new_line puts "\n" end |
#parents ⇒ Object
46 47 48 49 50 |
# File 'lib/objects/modules/workspace_commands.rb', line 46 def parents ps = [] ps << [parent, parent.parents] if has_parent? ps.flatten end |
#ping ⇒ Object
79 80 81 |
# File 'lib/objects/modules/workspace_commands.rb', line 79 def ping ssh_connect(is_ping: true, show_progress: true) end |
#pretty_description(is_active = true) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/objects/modules/workspace_commands.rb', line 83 def pretty_description(is_active = true) desc = '' list_attributes.each do |key, value| next unless respond_to?(value) || instance_variable_defined?("@#{value}") attribute_value = send(value) next unless attribute_value desc += "\t" desc += is_active ? key.to_s.resource_key : key.to_s.resource_key_inactive desc += "\s" * (12 - key.length) desc += is_active ? attribute_value.resource_value : attribute_value.resource_value_inactive desc += "\n" desc = desc unless is_active end desc end |
#resource_identifiers ⇒ Object
Helpers –
136 137 138 |
# File 'lib/objects/modules/workspace_commands.rb', line 136 def resource_identifiers resources.collect(&:identifier) end |
#run(*raw_commands) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/objects/modules/workspace_commands.rb', line 65 def run(*raw_commands) raise Bcome::Exception::MethodInvocationRequiresParameter, "Please specify commands when invoking 'run'" if raw_commands.empty? results = {} ssh_connect(show_progress: true) machines.pmap do |machine| commands = machine.do_run(raw_commands) results[machine.namespace] = commands end results end |
#ssh_connect(params = {}) ⇒ Object
5 6 7 |
# File 'lib/objects/modules/workspace_commands.rb', line 5 def ssh_connect(params = {}) ::Bcome::Ssh::Connector.connect(self, params) end |
#tree_descriptions ⇒ Object
162 163 164 165 |
# File 'lib/objects/modules/workspace_commands.rb', line 162 def tree_descriptions d = parent ? parent.tree_descriptions + [description] : [description] d.flatten end |
#visual_hierarchy ⇒ Object
152 153 154 155 156 157 158 159 160 |
# File 'lib/objects/modules/workspace_commands.rb', line 152 def visual_hierarchy tabs = 0 hierarchy = '' tree_descriptions.each do |d| hierarchy += "#{"\s\s\s" * tabs}|- #{d}\n" tabs += 1 end hierarchy end |
#workon(*ids) ⇒ Object
116 117 118 119 120 |
# File 'lib/objects/modules/workspace_commands.rb', line 116 def workon(*ids) resources.disable! ids.each { |id| resources.do_enable(id) } puts "\nYou are now working on '#{ids.join(', ')}\n".informational end |