Class: Blobby::HttpStore
- Inherits:
-
Object
- Object
- Blobby::HttpStore
- Defined in:
- lib/blobby/http_store.rb
Overview
A BLOB store backed by HTTP.
Defined Under Namespace
Classes: StoredObject
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #available? ⇒ Boolean
- #base_uri ⇒ Object
-
#initialize(base_url, options = {}) ⇒ HttpStore
constructor
A new instance of HttpStore.
- #with_http_connection ⇒ Object
Constructor Details
#initialize(base_url, options = {}) ⇒ HttpStore
10 11 12 13 14 |
# File 'lib/blobby/http_store.rb', line 10 def initialize(base_url, = {}) @base_url = base_url @base_url += "/" unless @base_url.end_with?("/") @max_retries = .fetch(:max_retries, 2) end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
16 17 18 |
# File 'lib/blobby/http_store.rb', line 16 def base_url @base_url end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
17 18 19 |
# File 'lib/blobby/http_store.rb', line 17 def max_retries @max_retries end |
Instance Method Details
#[](key) ⇒ Object
27 28 29 30 |
# File 'lib/blobby/http_store.rb', line 27 def [](key) KeyConstraint.must_allow!(key) StoredObject.new(self, key) end |
#available? ⇒ Boolean
19 20 21 22 23 24 25 |
# File 'lib/blobby/http_store.rb', line 19 def available? with_http_connection do true end rescue false end |
#base_uri ⇒ Object
32 33 34 |
# File 'lib/blobby/http_store.rb', line 32 def base_uri URI(base_url) end |
#with_http_connection ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/blobby/http_store.rb', line 36 def with_http_connection remaining_retry_intervals = retry_intervals(max_retries) begin Net::HTTP.start(base_uri.host, base_uri.port) do |http| yield http, base_uri.path end rescue *retryable_exceptions => e raise e if remaining_retry_intervals.empty? sleep(remaining_retry_intervals.shift) && retry end end |