Class: Sprinkle::Installers::ReplaceText
- Defined in:
- lib/sprinkle/installers/replace_text.rb
Overview
Replace text installer
This installer replaces a text with another one in a file.
Example Usage
Change ssh port in /etc/ssh/sshd_config
package :magic_beans do
replace_text 'Port 22', 'Port 2500', '/etc/ssh/sshd_config'
end
If you user has access to ‘sudo’ and theres a file that requires privileges, you can pass :sudo => true
package :magic_beans do
replace_text 'Port 22', 'Port 2500', '/etc/ssh/sshd_config', :sudo => true
end
A special verify step exists for this very installer its known as file_contains, it will test that a file indeed contains a substring that you send it.
Instance Attribute Summary collapse
-
#path ⇒ Object
:nodoc:.
-
#regex ⇒ Object
:nodoc:.
-
#text ⇒ Object
:nodoc:.
Attributes inherited from Installer
#delivery, #options, #package, #post, #pre
Instance Method Summary collapse
- #announce ⇒ Object
-
#initialize(parent, regex, text, path, options = {}, &block) ⇒ ReplaceText
constructor
:nodoc:.
Methods inherited from Installer
api, #commands_from_block, #defer, #escape_shell_arg, inherited, #install_sequence, #method_missing, #per_host?, #post_process, #process, subclasses, verify_api
Methods included from Sudo
#sudo?, #sudo_cmd, #sudo_stack
Methods included from Attributes
Constructor Details
#initialize(parent, regex, text, path, options = {}, &block) ⇒ ReplaceText
:nodoc:
35 36 37 38 39 40 |
# File 'lib/sprinkle/installers/replace_text.rb', line 35 def initialize(parent, regex, text, path, ={}, &block) #:nodoc: super parent, , &block @regex = regex @text = text @path = path end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Sprinkle::Installers::Installer
Instance Attribute Details
#path ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/sprinkle/installers/replace_text.rb', line 27 def path @path end |
#regex ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/sprinkle/installers/replace_text.rb', line 27 def regex @regex end |
#text ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/sprinkle/installers/replace_text.rb', line 27 def text @text end |
Instance Method Details
#announce ⇒ Object
42 43 44 |
# File 'lib/sprinkle/installers/replace_text.rb', line 42 def announce log "--> Replace '#{@regex}' with '#{@text}' in file #{@path}" end |