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_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #available? ⇒ Boolean
-
#initialize(uri, options = {}) ⇒ HttpStore
constructor
A new instance of HttpStore.
- #with_http_connection ⇒ Object
Constructor Details
#initialize(uri, options = {}) ⇒ HttpStore
Returns a new instance of HttpStore.
14 15 16 17 18 19 |
# File 'lib/blobby/http_store.rb', line 14 def initialize(uri, = {}) uri = URI(uri) uri = URI("#{uri}/") unless uri.to_s.end_with?("/") @base_uri = uri @max_retries = .fetch(:max_retries, 2) end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
21 22 23 |
# File 'lib/blobby/http_store.rb', line 21 def base_uri @base_uri end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
22 23 24 |
# File 'lib/blobby/http_store.rb', line 22 def max_retries @max_retries end |
Class Method Details
.from_uri(uri) ⇒ Object
10 11 12 |
# File 'lib/blobby/http_store.rb', line 10 def self.from_uri(uri) new(uri) end |
Instance Method Details
#[](key) ⇒ Object
32 33 34 35 |
# File 'lib/blobby/http_store.rb', line 32 def [](key) KeyConstraint.must_allow!(key) StoredObject.new(self, key) end |
#available? ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/blobby/http_store.rb', line 24 def available? with_http_connection do true end rescue false end |
#with_http_connection ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/blobby/http_store.rb', line 37 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 |