Class: Bcome::Bootup
- Inherits:
-
Object
- Object
- Bcome::Bootup
- Includes:
- Singleton
- Defined in:
- lib/objects/bootup.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#breadcrumbs ⇒ Object
readonly
Returns the value of attribute breadcrumbs.
Class Method Summary collapse
- .set_and_do(params, spawn_into_console = true) ⇒ Object
- .traverse(breadcrumbs = nil, _spawn_into_console = false) ⇒ Object
Instance Method Summary collapse
- #close_ssh_connections ⇒ Object
- #crumbs ⇒ Object
- #do ⇒ Object
- #estate ⇒ Object
- #estate_loaded? ⇒ Boolean
- #init_context(context) ⇒ Object
- #parser ⇒ Object
- #set(params, spawn_into_console = false) ⇒ Object
- #traverse(_starting_context) ⇒ Object
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
17 18 19 |
# File 'lib/objects/bootup.rb', line 17 def arguments @arguments end |
#breadcrumbs ⇒ Object (readonly)
Returns the value of attribute breadcrumbs.
17 18 19 |
# File 'lib/objects/bootup.rb', line 17 def @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( = nil, _spawn_into_console = false) spawn_into_console = false ::Bcome::Bootup.set_and_do({ breadcrumbs: }, spawn_into_console) end |
Instance Method Details
#close_ssh_connections ⇒ Object
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 |
#crumbs ⇒ Object
80 81 82 |
# File 'lib/objects/bootup.rb', line 80 def crumbs parser.crumbs end |
#do ⇒ Object
25 26 27 28 |
# File 'lib/objects/bootup.rb', line 25 def do context = crumbs.empty? ? init_context(estate) : traverse(estate) context end |
#estate ⇒ Object
62 63 64 |
# File 'lib/objects/bootup.rb', line 62 def estate @estate ||= ::Bcome::Node::Factory.instance.init_tree end |
#estate_loaded? ⇒ 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 |
#parser ⇒ Object
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 |