Permalink
Browse files

added simple File#remove_from method

  • Loading branch information...
1 parent 718cfbe commit cf82bca0a0a5a76751580985ce265a471a30e25c @kristianmandrup committed Sep 13, 2010
View
0 .document 100644 → 100755
No changes.
View
0 .gitignore 100644 → 100755
No changes.
View
0 .rspec 100644 → 100755
No changes.
View
0 LICENSE 100644 → 100755
No changes.
View
0 README.markdown 100644 → 100755
No changes.
View
0 Rakefile 100644 → 100755
No changes.
View
0 VERSION 100644 → 100755
No changes.
View
0 lib/sugar-high.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/alias.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/arguments.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/array.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/blank.rb 100644 → 100755
No changes.
View
6 lib/sugar-high/file.rb 100644 → 100755
@@ -35,6 +35,10 @@ def self.append path, content=nil, &block
f.puts content ||= yield
end
end
+
+ def self.remove_from file_name, content, &block
+ replace_content_from file_name, :content => content, :with => '', &block
+ end
# replaces content found at replacement_expr with content resulting from yielding block
# File.replace_content_from 'myfile.txt', where => /HelloWorld/, with => 'GoodBye'
@@ -150,7 +154,7 @@ def self.content options = {}, *args, &block
when String
args.first
when Hash
- options[:content] || yield if block
+ 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"
View
0 lib/sugar-high/hash.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/includes.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/kind_of.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/metaclass.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/methods.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/module.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/not.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/path.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/regexp.rb 100644 → 100755
No changes.
View
0 lib/sugar-high/rspec/configure.rb 100644 → 100755
No changes.
View
No changes.
View
0 spec/fixtures/empty.txt 100644 → 100755
No changes.
View
0 spec/fixtures/non-empty.txt 100644 → 100755
No changes.
View
0 spec/spec_helper.rb 100644 → 100755
No changes.
View
0 spec/sugar-high/alias_spec.rb 100644 → 100755
No changes.
View
0 spec/sugar-high/arguments_spec.rb 100644 → 100755
No changes.
View
0 spec/sugar-high/array_spec.rb 100644 → 100755
No changes.
View
0 spec/sugar-high/blank_spec.rb 100644 → 100755
No changes.
View
@@ -46,6 +46,18 @@
end
end
+ describe '#remove_from with String/Regexp argument that is content to remove' do
+ let(:replace_file) { fixture_file 'file.txt' }
+
+ it "should remove content from existing file" do
+ File.overwrite(replace_file) do
+ 'Hello You'
+ end
+ File.remove_from replace_file, 'You'
+ File.read(replace_file).should_not match /You/
+ end
+ end
+
describe '#insert_into' do
let(:insertion_file) { fixture_file 'insertion.txt' }
@@ -64,28 +76,29 @@
File.insert_into insertion_file, :before => 'Goodbye' do
'Hello'
end
+ File.read(insertion_file).should match /Hello\s+Goodbye/
end
it "should insert Hello before Goodbye using a content string arg" do
File.insert_into insertion_file, "Hello ", :before => 'Goodbye'
- File.read(insertion_file).should_not match /Hello Goodbye/
+ File.read(insertion_file).should match /Hello\s+Goodbye/
end
it "should insert Hello before Goodbye using a :content option" do
- File.insert_into insertion_file, :content => 'Hello ', :before => 'Goodbye'
- File.read(insertion_file).should_not match /Hello Goodbye/
+ File.insert_into insertion_file, :content => 'Hello', :before => 'Goodbye'
+ File.read(insertion_file).should match /Hello\s+Goodbye/
end
it "should insert Hello before Goodbye using a block as content to insert" do
File.insert_into insertion_file, :before => 'Goodbye' do
- 'Hello '
+ 'Hello'
end
- File.read(insertion_file).should_not match /Hello Goodbye/
+ File.read(insertion_file).should match /Hello\s+Goodbye/
end
it "should insert Hello after Goodbye using a :with option and a Regexp for the after expression" do
File.insert_into insertion_file, :content => ' Hello', :after => /Goodbye/
- File.read(insertion_file).should_not match /Goodbye Hello/
+ File.read(insertion_file).should match /Goodbye\s+Hello/
end
end
end
View
0 spec/sugar-high/file/file_spec.rb 100644 → 100755
No changes.
View
0 spec/sugar-high/includes_spec.rb 100644 → 100755
No changes.
View
0 spec/sugar-high/kind_of_spec.rb 100644 → 100755
No changes.
View
0 spec/sugar-high/methods_spec.rb 100644 → 100755
No changes.
View
0 spec/sugar-high/module_spec.rb 100644 → 100755
No changes.
View
0 spec/sugar-high/path_spec.rb 100644 → 100755
No changes.
View
0 spec/sugar-high/regexp_spec.rb 100644 → 100755
No changes.
View
4 sugar-high.gemspec 100644 → 100755
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{sugar-high}
- s.version = "0.2.2"
+ s.version = "0.2.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Kristian Mandrup"]
- s.date = %q{2010-09-04}
+ s.date = %q{2010-09-10}
s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
s.email = %q{kmandrup@gmail.com}
s.extra_rdoc_files = [

0 comments on commit cf82bca

Please sign in to comment.