Class: Serverkit::Resources::Line

Inherits:
Base
  • Object
show all
Defined in:
lib/serverkit/resources/line.rb

Overview

Ensure a particular line is in a file, or replace an existing line using regexp.

Examples:

Example line resource that ensures a line is in /etc/sudoers

- type: line
  path: /etc/sudoers
  line: "#includedir /etc/sudoers.d"

Defined Under Namespace

Classes: Content

Constant Summary collapse

DEFAULT_STATE =
"present".freeze

Instance Attribute Summary

Attributes inherited from Base

#attributes, #backend, #check_result, #recheck_result, #recipe

Instance Method Summary collapse

Methods inherited from Base

abstract_class?, #all_errors, attribute, #check_command, #check_command_from_identifier, #get_command_from_identifier, #handlers, #id, #initialize, #notifiable?, #run_apply, #run_check, #successful?, #successful_on_check?, #successful_on_recheck?, #to_a

Constructor Details

This class inherits a constructor from Serverkit::Resources::Base

Instance Method Details

#applyObject

Note:

Override



22
23
24
25
26
27
28
29
30
# File 'lib/serverkit/resources/line.rb', line 22

def apply
  if has_correct_file?
    if validation_script
      update_remote_file_content_with_validation
    else
      update_remote_file_content_without_validation
    end
  end
end

#checkObject

Note:

Override



33
34
35
# File 'lib/serverkit/resources/line.rb', line 33

def check
  has_correct_file? && has_correct_line?
end