Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #56 from fastly/gschorkopf/soft-purge
Browse files Browse the repository at this point in the history
Adds soft purging from fastly-ruby client
  • Loading branch information
lanej committed Jun 2, 2016
2 parents 3b73476 + 2c28c48 commit 8245aa8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ end

### Purges

Any object that inherits from ActiveRecord will have `purge_all` and `table_key` class methods available as well as `purge` and `purge_all` instance methods.
Any object that inherits from ActiveRecord will have `purge_all`, `soft_purge_all`, and `table_key` class methods available as well as `purge`, `soft_purge`, `purge_all`, and `soft_purge_all` instance methods.

Example usage is show below.

Expand Down
12 changes: 12 additions & 0 deletions lib/fastly-rails/active_record/surrogate_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def purge_all
FastlyRails.purge_by_key(table_key)
end

def soft_purge_all
FastlyRails.purge_by_key(table_key, true)
end

def table_key
table_name
end
Expand All @@ -33,10 +37,18 @@ def purge
FastlyRails.purge_by_key(record_key)
end

def soft_purge
FastlyRails.purge_by_key(record_key, true)
end

def purge_all
self.class.purge_all
end

def soft_purge_all
self.class.soft_purge_all
end

def fastly_service_identifier
self.class.fastly_service_identifier
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fastly-rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FastlyRails
VERSION = "0.6.0"
VERSION = "0.7.0"
end
4 changes: 2 additions & 2 deletions test/dummy/test/models/book_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

it "should have Fastly::SurrogateKey instance methods" do

[:record_key, :table_key, :purge, :purge_all].each do |method|
[:record_key, :table_key, :purge, :purge_all, :soft_purge, :soft_purge_all].each do |method|
assert_respond_to book, method
end

end

it "should have Fastly::SurrogateKey class methods" do

[:table_key, :purge_all].each do |method|
[:table_key, :purge_all, :soft_purge_all].each do |method|
assert_respond_to Book, method
end

Expand Down
10 changes: 10 additions & 0 deletions test/fastly-rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@
end
end

it 'allows soft purging' do
FastlyRails.stub(:client, client) do
FastlyRails.stub(:purging_enabled?, true) do
client.expect(:purge_by_key, nil, [key, true])
FastlyRails.purge_by_key(key, true)
client.verify
end
end
end

it 'does nothing when purging is disabled' do
configuration.purging_enabled = false
FastlyRails.stub(:client, client) do
Expand Down

1 comment on commit 8245aa8

@samratjp
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much needed and timely - thanks for this 💯

Please sign in to comment.