Class: Chef::Knife::NodeEditor

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/knife/core/node_editor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, ui, config) ⇒ NodeEditor

Returns a new instance of NodeEditor.



31
32
33
# File 'lib/chef/knife/core/node_editor.rb', line 31

def initialize(node, ui, config)
  @node, @ui, @config = node, ui, config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



29
30
31
# File 'lib/chef/knife/core/node_editor.rb', line 29

def config
  @config
end

#nodeObject (readonly)

Returns the value of attribute node.



27
28
29
# File 'lib/chef/knife/core/node_editor.rb', line 27

def node
  @node
end

#uiObject (readonly)

Returns the value of attribute ui.



28
29
30
# File 'lib/chef/knife/core/node_editor.rb', line 28

def ui
  @ui
end

Instance Method Details

#edit_nodeObject



35
36
37
38
39
40
41
42
# File 'lib/chef/knife/core/node_editor.rb', line 35

def edit_node
  abort "You specified the --disable_editing option, nothing to edit" if config[:disable_editing]
  assert_editor_set!

  updated_node_data = @ui.edit_data(view)
  apply_updates(updated_node_data)
  @updated_node
end

#updated?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
# File 'lib/chef/knife/core/node_editor.rb', line 44

def updated?
  pristine_copy = Chef::JSONCompat.parse(Chef::JSONCompat.to_json(node))
  updated_copy  = Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@updated_node))
  unless pristine_copy == updated_copy
    updated_properties = %w{name normal chef_environment run_list default override automatic}.reject do |key|
       pristine_copy[key] == updated_copy[key]
    end
  end
  ( pristine_copy != updated_copy ) && updated_properties
end