Class: Object

Inherits:
BasicObject
Includes:
Bcome::CommandHelper
Defined in:
lib/object.rb

Instance Method Summary collapse

Methods included from Bcome::CommandHelper

#run_local

Instance Method Details

#available_resources_options_stringObject



49
50
51
# File 'lib/object.rb', line 49

def available_resources_options_string
  "Please select from one of '#{all_items.join(', ')}'"
end

#become(object) ⇒ Object



14
15
16
# File 'lib/object.rb', line 14

def become(object)
  BECOME.set(object, self)
end

#become_identifierObject



10
11
12
# File 'lib/object.rb', line 10

def become_identifier
  ::START_PROMPT
end

#describeObject



53
54
55
56
57
58
59
60
# File 'lib/object.rb', line 53

def describe
  if self.respond_to?(:do_describe)
    message = "\nCollection Key: #{reference_key}\n\nResource: #{self.do_describe}".colorize(:green)
  else
    message = "\nNothing to describe. Use 'list' to see namespace options".headsup unless self.respond_to?(:do_describe)
  end
  puts message
end

#highlight?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/object.rb', line 45

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

#listObject Also known as: ls



5
6
7
# File 'lib/object.rb', line 5

def list
  BOOT.send(:list)  ### Our starting point in the hierarchy... maybe this is all ultimately configurable?
end


41
42
43
# File 'lib/object.rb', line 41

def menu
  ::RENDER.menu(menu_items)
end


30
31
32
33
34
35
36
37
38
39
# File 'lib/object.rb', line 30

def menu_items
  [
    { :command => "list / ls", :description => "List all available resources at the current context." },
    { :command => "describe", :description => "Describe the resource object at the current context." },
    { :command => "workon' / w", :description => "Select a resource object, and switch to its context.", :usage => "workon 'identifier'" },
    { :command => "exit", :description => "Close the current context" },
    { :command => "exit!", :description => "Close all contexts, and exit Become."},
    { :command => "local", :description => "Execute a shell command on your local machine.", :usage => 'local "command"'}
  ]
end

#set_irb_prompt(conf) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/object.rb', line 62

def set_irb_prompt(conf)
  conf[:PROMPT][:CUSTOM] = {
    :PROMPT_N => "\e[1m:\e[m ",
    :PROMPT_I => "\e[1m#{BECOME.irb_prompt} >\e[m ",
    :PROMPT_C => "\e[1m#{BECOME.irb_prompt} >\e[m ",
    :RETURN => ::VERBOSE ? "%s \n" : "\n"
  }
  conf[:PROMPT_MODE] = :CUSTOM
end

#workon(identifier) ⇒ Object Also known as: w



18
19
20
21
22
23
24
25
26
27
# File 'lib/object.rb', line 18

def workon(identifier)
  resource = resource_for_identifier(identifier)

  unless resource
    puts "No matching #{collection_key} for identifier '#{identifier}'. #{available_resources_options_string}".failure
  else
    puts "\\ \nFrom #{resource.reference_key}, working on #{identifier}\n".command
    become(resource)
  end
end