Skip to content

Commit

Permalink
Merge pull request #10 from neighborland/replace-nil
Browse files Browse the repository at this point in the history
Make collection argument to Fragment#replace optional
  • Loading branch information
teeparham committed Apr 18, 2019
2 parents 32390f7 + c79b8b9 commit cbe21a0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/cache_rocket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def cache_replace(name = {}, options = {}, &block)
safe_concat \
Fragment.new(
fragment_for(cache_fragment_name(name, name_options), options, &block)
).replace(replace_hash, nil).to_s.html_safe
).replace(replace_hash).to_s.html_safe

nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cache_rocket/fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def gsub!(key, value)
@value.gsub! key, value
end

def replace(hash, collection)
def replace(hash, collection = nil)
if collection
replace_collection collection, hash
else
Expand Down
6 changes: 3 additions & 3 deletions test/fragment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FragmentTest < MiniTest::Spec
it "replace cache keys from hash" do
cr_key = Fragment.new(nil).cache_replace_key(:xx)
fragment = Fragment.new("hey #{cr_key} hey.")
fragment.replace({ xx: "yo" }, nil)
fragment.replace(xx: "yo")
assert_equal "hey yo hey.", fragment.to_s
end

Expand All @@ -39,8 +39,8 @@ def last5(object)

it "does not modify initialized value" do
value = "Hi #{Fragment.new(nil).cache_replace_key(:x)}"
assert_equal "Hi 1", Fragment.new(value).replace({ x: "1" }, nil).to_s
assert_equal "Hi 2", Fragment.new(value).replace({ x: "2" }, nil).to_s
assert_equal "Hi 1", Fragment.new(value).replace(x: "1").to_s
assert_equal "Hi 2", Fragment.new(value).replace(x: "2").to_s
end
end
end
Expand Down

0 comments on commit cbe21a0

Please sign in to comment.