class Chef::Util::Editor
Attributes
Public Class Methods
Source
# File lib/chef/util/editor.rb, line 24 def initialize(lines) @lines = lines.to_a.clone end
Public Instance Methods
Source
# File lib/chef/util/editor.rb, line 28 def append_line_after(search, line_to_append) lines = [] @lines.each do |line| lines << line lines << line_to_append if line.match(search) end (lines.length - @lines.length).tap { @lines = lines } end
Source
# File lib/chef/util/editor.rb, line 39 def append_line_if_missing(search, line_to_append) count = 0 unless @lines.find { |line| line.match(search) } count = 1 @lines << line_to_append end count end
Source
# File lib/chef/util/editor.rb, line 50 def remove_lines(search) count = 0 @lines.delete_if do |line| count += 1 if line.match(search) end count end
Source
# File lib/chef/util/editor.rb, line 60 def replace(search, replace) count = 0 @lines.map! do |line| if line.match(search) count += 1 line.gsub!(search, replace) else line end end count end
Source
# File lib/chef/util/editor.rb, line 75 def replace_lines(search, replace) count = 0 @lines.map! do |line| if line.match(search) count += 1 replace else line end end count end