borrower 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,14 +23,23 @@ module Borrower::DSL
23
23
  # @example borrow and merge source to destination
24
24
  # borrow "source/file", to: "file/destination", merge: true
25
25
  #
26
+ # @example borrow and gsub all exclamation marks
27
+ # borrow "source/file", to: "file/destination" do |content|
28
+ # content.gsub("!", '.')
29
+ # end
30
+ #
26
31
  # @param [String] path
27
32
  # @param [Hash] args
28
33
  # @option args [String] :to the destination path
29
34
  # @option args [Boolean] :merge wether to merge or not, defaults to `false`
30
35
  # @return [Void]
31
- def borrow path, args
36
+ def borrow path, args={}, &block
32
37
  destination = args.delete(:to) { raise ArgumentError, "missing 'to:' argument" }
33
- Borrower.put Borrower.take(path), destination , args
38
+ content = Borrower.take(path)
39
+ if block_given?
40
+ content = yield content
41
+ end
42
+ Borrower.put content, destination, args
34
43
  end
35
44
 
36
45
  end
@@ -1,3 +1,3 @@
1
1
  module Borrower
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -47,4 +47,12 @@ describe Borrower do
47
47
  expect{ borrow( "foo", away: "bar" )}.to raise_error(ArgumentError)
48
48
  end
49
49
 
50
+ it "yields content when passed a block" do
51
+ borrow local_file, to: file_destination do |content|
52
+ content + " foo"
53
+ end
54
+
55
+ Borrower.take( file_destination ).should == "Hi I'm a file foo"
56
+ end
57
+
50
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: borrower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: