Class: Bcome::Bootup

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/objects/bootup.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



17
18
19
# File 'lib/objects/bootup.rb', line 17

def arguments
  @arguments
end

Returns the value of attribute breadcrumbs.



17
18
19
# File 'lib/objects/bootup.rb', line 17

def breadcrumbs
  @breadcrumbs
end

Class Method Details

.set_and_do(params, spawn_into_console = true) ⇒ Object



5
6
7
8
# File 'lib/objects/bootup.rb', line 5

def self.set_and_do(params, spawn_into_console = true)
  instance.set(params, spawn_into_console)
  instance.do
end

.traverse(breadcrumbs = nil, _spawn_into_console = false) ⇒ Object



10
11
12
13
# File 'lib/objects/bootup.rb', line 10

def self.traverse(breadcrumbs = nil, _spawn_into_console = false)
  spawn_into_console = false
  ::Bcome::Bootup.set_and_do({ breadcrumbs: breadcrumbs }, spawn_into_console)
end

Instance Method Details

#close_ssh_connectionsObject



70
71
72
73
74
# File 'lib/objects/bootup.rb', line 70

def close_ssh_connections
  return unless estate_loaded?

  estate.close_ssh_connections
end

#crumbsObject



80
81
82
# File 'lib/objects/bootup.rb', line 80

def crumbs
  parser.crumbs
end

#doObject



25
26
27
28
# File 'lib/objects/bootup.rb', line 25

def do
  context = crumbs.empty? ? init_context(estate) : traverse(estate)
  context
end

#estateObject



62
63
64
# File 'lib/objects/bootup.rb', line 62

def estate
  @estate ||= ::Bcome::Node::Factory.instance.init_tree
end

#estate_loaded?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/objects/bootup.rb', line 66

def estate_loaded?
  !@estate.nil?
end

#init_context(context) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/objects/bootup.rb', line 30

def init_context(context)
  if @spawn_into_console
    ::Bcome::Workspace.instance.set(context: context, show_welcome: true)
  else
    context
  end
end

#parserObject



76
77
78
# File 'lib/objects/bootup.rb', line 76

def parser
  ::Bcome::Parser::BreadCrumb.new(@breadcrumbs)
end

#set(params, spawn_into_console = false) ⇒ Object



19
20
21
22
23
# File 'lib/objects/bootup.rb', line 19

def set(params, spawn_into_console = false)
  @breadcrumbs = params[:breadcrumbs]
  @arguments = params[:arguments]
  @spawn_into_console = spawn_into_console
end

#traverse(_starting_context) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/objects/bootup.rb', line 38

def traverse(_starting_context)
  starting_context = estate
  crumbs.each_with_index do |crumb, _index|
    # Some contexts' resources are loaded dynamically and do not come from the estate config. As we're traversing, we'll need to load
    # them if necessary
    starting_context.load_nodes if starting_context.inventory? && !starting_context.nodes_loaded?

    # Attempt to load our next context resource
    next_context = starting_context.resources.active.first if crumb == 'first'
    next_context ||= starting_context.resource_for_identifier(crumb)

    # Our current breadcrumb is not a node, and so we'll attempt to invoke a method call on the previous
    # e.g. given resource:foo, then invoke 'foo' on 'resource'
    unless next_context
      puts "\n" # clean any trailing loading bars
      starting_context.invoke(crumb, @arguments)
      return
    end
    starting_context = next_context
  end
  # Set our workspace to our last context - we're not invoking a method call and so we're entering a console session
  init_context(starting_context)
end