borrower 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/borrower.rb +11 -2
- data/lib/borrower/version.rb +1 -1
- data/spec/borrower_spec.rb +8 -0
- metadata +1 -1
data/lib/borrower.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/borrower/version.rb
CHANGED
data/spec/borrower_spec.rb
CHANGED
@@ -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
|