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.



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

def arguments
  @arguments
end

Returns the value of attribute breadcrumbs.



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

def breadcrumbs
  @breadcrumbs
end

Class Method Details

.set_and_do(params, spawn_into_console = true) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/objects/bootup.rb', line 3

def self.set_and_do(params, spawn_into_console = true)
  instance.set(params, spawn_into_console)
  instance.do
rescue Bcome::Exception::Base => e
  puts e.pretty_display
rescue Excon::Error::Socket => e
  puts "\nNo network access - please check your connection and try again\n".red
end

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



12
13
14
15
# File 'lib/objects/bootup.rb', line 12

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

#crumbsObject



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

def crumbs
  parser.crumbs
end

#doObject



27
28
29
30
# File 'lib/objects/bootup.rb', line 27

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

#estateObject



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

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

#init_context(context) ⇒ Object



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

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

#parserObject



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

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

#set(params, spawn_into_console = false) ⇒ Object



21
22
23
24
25
# File 'lib/objects/bootup.rb', line 21

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

#traverse(_starting_context) ⇒ Object



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

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.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
      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