Class: Bcome::Workspace

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorkspace

Returns a new instance of Workspace.



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

def initialize
  @context = nil
  @console_set = false
  @estate = nil
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#estateObject (readonly)

Returns the value of attribute estate.



7
8
9
# File 'lib/objects/workspace.rb', line 7

def estate
  @estate
end

Instance Method Details

#console_set!Object



39
40
41
# File 'lib/objects/workspace.rb', line 39

def console_set!
  @console_set = true
end

#console_set?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/objects/workspace.rb', line 43

def console_set?
  @console_set
end

#default_promptObject



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

def default_prompt
  'bcome'
end

#has_context?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/objects/workspace.rb', line 55

def has_context?
  !context.nil?
end

#irb_promptObject



59
60
61
# File 'lib/objects/workspace.rb', line 59

def irb_prompt
  @context ? @context.prompt_breadcrumb : default_prompt
end

#object_is_current_context?(object) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/objects/workspace.rb', line 47

def object_is_current_context?(object)
  @context == object
end

#set(params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/objects/workspace.rb', line 15

def set(params)
  init_irb unless console_set?

  @context = params[:context]
  @context.load_nodes if @context.inventory? && !@context.nodes_loaded?

  main_context = IRB.conf[:MAIN_CONTEXT]

  @context.irb_workspace = main_context.workspace if main_context
  @context.previous_irb_workspace = params[:current_context] if params[:current_context]

  show_welcome if params[:show_welcome]

  spawn_into_console_for_context
  nil
end

#show_welcomeObject



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

def show_welcome
  puts "\n\n"
  puts "Welcome to bcome v#{::Bcome::Version.release}".bc_yellow
  puts "\nType\s" + 'menu'.underline + "\sfor a command list, or\s" + 'registry'.underline + "\sfor your custom tasks."
  puts "\n\n"
end

#spawn_into_console_for_contextObject



51
52
53
# File 'lib/objects/workspace.rb', line 51

def spawn_into_console_for_context
  ::IRB.start_session(self, @context)
end