lib/sugar-high/file.rb in sugar-high-0.2.1 vs lib/sugar-high/file.rb in sugar-high-0.2.2
- old
+ new
@@ -37,20 +37,20 @@
end
# replaces content found at replacement_expr with content resulting from yielding block
# File.replace_content_from 'myfile.txt', where => /HelloWorld/, with => 'GoodBye'
def self.replace_content_from file_name, options = {}, &block
- replacement_expr = options[:where]
+ replacement_expr = options[:where] || options[:content]
new_content = options[:with]
replacement_expr = case replacement_expr
when Regexp
replacement_expr
when String
/#{Regexp.escape(replacement_expr)}/
else
- raise ArgumentError, "Content to be replaced must be specified as either a String or Regexp in a :where option"
+ raise ArgumentError, "Content to be replaced must be specified as either a String or Regexp in a :where or :content option"
end
# get existing file content
content = File.read file_name
@@ -148,10 +148,10 @@
def self.content options = {}, *args, &block
case args.first
when String
args.first
when Hash
- options[:content]
+ options[:content] || yield if block
else
return yield if block
raise ArgumentError, "You must supply content to insert, either as a String before the options hash, a :content option or a block"
end
end