module Bcome::WorkspaceCommands

Public Instance Methods

cd(identifier) click to toggle source
# 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!() click to toggle source
# 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) click to toggle source
# File lib/objects/modules/workspace_commands.rb, line 101
def disable(*ids)
  ids.each { |id| resources.do_disable(id) }
end
disable!() click to toggle source
# File lib/objects/modules/workspace_commands.rb, line 122
def disable!
  resources.disable!
  resources.each(&:disable!)
  nil
end
enable(*ids) click to toggle source
# File lib/objects/modules/workspace_commands.rb, line 105
def enable(*ids)
  ids.each { |id| resources.do_enable(id) }
end
enable!() click to toggle source
# File lib/objects/modules/workspace_commands.rb, line 128
def enable!
  resources.enable!
  resources.each(&:enable!)
  nil
end
interactive() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/objects/modules/workspace_commands.rb, line 167
def new_line
  puts "\n"
end
parents() click to toggle source
# File lib/objects/modules/workspace_commands.rb, line 46
def parents
  ps = []
  ps << [parent, parent.parents] if has_parent?
  ps.flatten
end
ping() click to toggle source
# 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) click to toggle source
# 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() click to toggle source

Helpers –

# File lib/objects/modules/workspace_commands.rb, line 136
def resource_identifiers
  resources.collect(&:identifier)
end
run(*raw_commands) click to toggle source
# 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 = {}) click to toggle source
# File lib/objects/modules/workspace_commands.rb, line 5
def ssh_connect(params = {})
  ::Bcome::Ssh::Connector.connect(self, params)
end
tree_descriptions() click to toggle source
# File lib/objects/modules/workspace_commands.rb, line 162
def tree_descriptions
  d = parent ? parent.tree_descriptions + [description] : [description]
  d.flatten
end
visual_hierarchy() click to toggle source
# 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) click to toggle source
# 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