Class: Shell::ShellSession

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/chef/shell/shell_session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShellSession

Returns a new instance of ShellSession.



45
46
47
48
49
# File 'lib/chef/shell/shell_session.rb', line 45

def initialize
  @node_built = false
  formatter = Chef::Formatters.new(Chef::Config.formatter, STDOUT, STDERR)
  @events = Chef::EventDispatch::Dispatcher.new(formatter)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



43
44
45
# File 'lib/chef/shell/shell_session.rb', line 43

def client
  @client
end

#compileObject

Returns the value of attribute compile.



42
43
44
# File 'lib/chef/shell/shell_session.rb', line 42

def compile
  @compile
end

#json_configurationObject

Returns the value of attribute json_configuration.



42
43
44
# File 'lib/chef/shell/shell_session.rb', line 42

def json_configuration
  @json_configuration
end

#nodeObject

Returns the value of attribute node.



42
43
44
# File 'lib/chef/shell/shell_session.rb', line 42

def node
  @node
end

#node_attributesObject

Returns the value of attribute node_attributes.



43
44
45
# File 'lib/chef/shell/shell_session.rb', line 43

def node_attributes
  @node_attributes
end

#recipeObject

Returns the value of attribute recipe.



42
43
44
# File 'lib/chef/shell/shell_session.rb', line 42

def recipe
  @recipe
end

#run_contextObject



80
81
82
# File 'lib/chef/shell/shell_session.rb', line 80

def run_context
  @run_context ||= rebuild_context
end

Class Method Details

.inspectObject

rubocop:disable Lint/NestedMethodDefinition



133
134
135
# File 'lib/chef/shell/shell_session.rb', line 133

def @node.inspect # rubocop:disable Lint/NestedMethodDefinition
  "<Chef::Node:0x#{object_id.to_s(16)} @name=\"#{name}\">"
end

.session_type(type = nil) ⇒ Object



37
38
39
40
# File 'lib/chef/shell/shell_session.rb', line 37

def self.session_type(type = nil)
  @session_type = type if type
  @session_type
end

Instance Method Details

#cookbook_loaderObject



88
89
90
# File 'lib/chef/shell/shell_session.rb', line 88

def cookbook_loader
  nil
end

#definitionsObject



84
85
86
# File 'lib/chef/shell/shell_session.rb', line 84

def definitions
  nil
end

#node_built?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/chef/shell/shell_session.rb', line 51

def node_built?
  !!@node_built
end

#rebuild_contextObject



96
97
98
# File 'lib/chef/shell/shell_session.rb', line 96

def rebuild_context
  raise "Not Implemented! :rebuild_collection should be implemented by subclasses"
end

#reset!Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/chef/shell/shell_session.rb', line 55

def reset!
  loading do
    rebuild_node
    @node = client.node
    shorten_node_inspect
    Shell::Extensions.extend_context_node(@node)
    rebuild_context
    node.consume_attributes(node_attributes) if node_attributes
    @recipe = Chef::Recipe.new(nil, nil, run_context)
    Shell::Extensions.extend_context_recipe(@recipe)
    @node_built = true
  end
end

#resource_collectionObject



74
75
76
# File 'lib/chef/shell/shell_session.rb', line 74

def resource_collection
  run_context.resource_collection
end

#save_nodeObject



92
93
94
# File 'lib/chef/shell/shell_session.rb', line 92

def save_node
  raise "Not Supported! #{self.class.name} doesn't support #save_node, maybe you need to run #{ChefUtils::Dist::Infra::SHELL} in client mode?"
end