Module: Prepper::Tools::Text
- Included in:
- Package
- Defined in:
- lib/prepper/tools/text.rb
Overview
text related helpers
Instance Method Summary collapse
-
#append_text(text, path) ⇒ Object
append text to a file.
-
#has_text?(text, path) ⇒ Boolean
returns a verifier command to test the presence of a string in a file.
Instance Method Details
#append_text(text, path) ⇒ Object
append text to a file
8 9 10 |
# File 'lib/prepper/tools/text.rb', line 8 def append_text(text, path) @commands << Command.new("/bin/echo -e '#{text}' | sudo tee -a #{path}", verifier: has_text?(text, path)) end |
#has_text?(text, path) ⇒ Boolean
returns a verifier command to test the presence of a string in a file
15 16 17 18 |
# File 'lib/prepper/tools/text.rb', line 15 def has_text?(text, path) regex = Regexp.escape(text) Command.new("grep -qPzo '^#{regex}$' #{path} ||", sudo: true) end |