Module: FileMutate::RemoveContent

Defined in:
lib/file_mutate/remove_content.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#remove_content(options = nil, &block) ⇒ Object Also known as: remove



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/file_mutate/remove_content.rb', line 3

def remove_content options=nil, &block
  opt_str = case options
            when String
              options
            when Hash
              content = options[:content] || options[:where]
              raise ArgumentError, "Bad :content value in Hash" if !content || content.strip.empty?
              content.strip
            else
              raise ArgumentError, "non-block argument must be either String or Hash with a :content option" if !block
            end
  content = block ? yield : opt_str

  File.remove_content_from self.path, :content => content, :with => '', &block
end