Class: ChefCLI::PolicyfileServices::Undelete
- Inherits:
-
Object
- Object
- ChefCLI::PolicyfileServices::Undelete
- Defined in:
- lib/chef-cli/policyfile_services/undelete.rb
Instance Attribute Summary collapse
-
#chef_config ⇒ Object
readonly
Returns the value of attribute chef_config.
-
#ui ⇒ Object
readonly
Returns the value of attribute ui.
-
#undo_record_id ⇒ Object
readonly
Returns the value of attribute undo_record_id.
Instance Method Summary collapse
- #http_client ⇒ Object
-
#initialize(undo_record_id: nil, config: nil, ui: nil) ⇒ Undelete
constructor
A new instance of Undelete.
-
#list ⇒ Object
In addition to the #run method, this class also has #list as a public entry point.
- #run ⇒ Object
- #undo_stack ⇒ Object
Constructor Details
#initialize(undo_record_id: nil, config: nil, ui: nil) ⇒ Undelete
Returns a new instance of Undelete.
32 33 34 35 36 37 38 39 |
# File 'lib/chef-cli/policyfile_services/undelete.rb', line 32 def initialize(undo_record_id: nil, config: nil, ui: nil) @chef_config = config @ui = ui @undo_record_id = undo_record_id @http_client = nil @undo_stack = nil end |
Instance Attribute Details
#chef_config ⇒ Object (readonly)
Returns the value of attribute chef_config.
28 29 30 |
# File 'lib/chef-cli/policyfile_services/undelete.rb', line 28 def chef_config @chef_config end |
#ui ⇒ Object (readonly)
Returns the value of attribute ui.
26 27 28 |
# File 'lib/chef-cli/policyfile_services/undelete.rb', line 26 def ui @ui end |
#undo_record_id ⇒ Object (readonly)
Returns the value of attribute undo_record_id.
30 31 32 |
# File 'lib/chef-cli/policyfile_services/undelete.rb', line 30 def undo_record_id @undo_record_id end |
Instance Method Details
#http_client ⇒ Object
73 74 75 76 77 |
# File 'lib/chef-cli/policyfile_services/undelete.rb', line 73 def http_client @http_client ||= Chef::ServerAPI.new(chef_config.chef_server_url, signing_key_filename: chef_config.client_key, client_name: chef_config.node_name) end |
#list ⇒ Object
In addition to the #run method, this class also has #list as a public entry point. This prints the list of undoable items, with descriptions.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/chef-cli/policyfile_services/undelete.rb', line 43 def list if undo_stack.empty? ui.err("Nothing to undo.") else = [] undo_stack.each_with_id do |, undo_record| .unshift("#{}: #{undo_record.description}") end .each { |m| ui.msg(m) } end end |
#run ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/chef-cli/policyfile_services/undelete.rb', line 55 def run if undo_record_id if undo_stack.has_id?(undo_record_id) undo_stack.delete(undo_record_id) { |undo_record| restore(undo_record) } else ui.err("No undo record with id '#{undo_record_id}' exists") end else undo_stack.pop { |undo_record| restore(undo_record) } end rescue => e raise UndeleteError.new("Failed to undelete.", e) end |
#undo_stack ⇒ Object
69 70 71 |
# File 'lib/chef-cli/policyfile_services/undelete.rb', line 69 def undo_stack @undo_stack ||= Policyfile::UndoStack.new end |