Class: Dragonfly::AzureDataStore
- Inherits:
-
Object
- Object
- Dragonfly::AzureDataStore
- Defined in:
- lib/dragonfly/azure_data_store.rb,
lib/dragonfly/azure_data_store/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#account_name ⇒ Object
Returns the value of attribute account_name.
-
#container_name ⇒ Object
Returns the value of attribute container_name.
-
#legacy_meta ⇒ Object
Returns the value of attribute legacy_meta.
-
#root_path ⇒ Object
Returns the value of attribute root_path.
-
#store_meta ⇒ Object
Returns the value of attribute store_meta.
-
#url_host ⇒ Object
Returns the value of attribute url_host.
-
#url_scheme ⇒ Object
Returns the value of attribute url_scheme.
Instance Method Summary collapse
- #destroy(uid) ⇒ Object
-
#initialize(opts = {}) ⇒ AzureDataStore
constructor
A new instance of AzureDataStore.
- #read(uid) ⇒ Object
- #url_for(uid, opts = {}) ⇒ Object
- #write(content, _opts = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ AzureDataStore
Returns a new instance of AzureDataStore.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dragonfly/azure_data_store.rb', line 12 def initialize(opts = {}) @account_name = opts[:account_name] @access_key = opts[:access_key] @container_name = opts[:container_name] @root_path = opts[:root_path] @url_scheme = opts[:url_scheme] || 'http' @url_host = opts[:url_host] @store_meta = opts[:store_meta].nil? ? true : opts[:store_meta] @legacy_meta = opts[:legacy_meta] end |
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key.
9 10 11 |
# File 'lib/dragonfly/azure_data_store.rb', line 9 def access_key @access_key end |
#account_name ⇒ Object
Returns the value of attribute account_name.
9 10 11 |
# File 'lib/dragonfly/azure_data_store.rb', line 9 def account_name @account_name end |
#container_name ⇒ Object
Returns the value of attribute container_name.
9 10 11 |
# File 'lib/dragonfly/azure_data_store.rb', line 9 def container_name @container_name end |
#legacy_meta ⇒ Object
Returns the value of attribute legacy_meta.
9 10 11 |
# File 'lib/dragonfly/azure_data_store.rb', line 9 def @legacy_meta end |
#root_path ⇒ Object
Returns the value of attribute root_path.
9 10 11 |
# File 'lib/dragonfly/azure_data_store.rb', line 9 def root_path @root_path end |
#store_meta ⇒ Object
Returns the value of attribute store_meta.
9 10 11 |
# File 'lib/dragonfly/azure_data_store.rb', line 9 def @store_meta end |
#url_host ⇒ Object
Returns the value of attribute url_host.
9 10 11 |
# File 'lib/dragonfly/azure_data_store.rb', line 9 def url_host @url_host end |
#url_scheme ⇒ Object
Returns the value of attribute url_scheme.
9 10 11 |
# File 'lib/dragonfly/azure_data_store.rb', line 9 def url_scheme @url_scheme end |
Instance Method Details
#destroy(uid) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/dragonfly/azure_data_store.rb', line 54 def destroy(uid) storage.delete_blob(container.name, full_path(uid)) true rescue Azure::Core::Http::HTTPError false end |
#read(uid) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dragonfly/azure_data_store.rb', line 34 def read(uid) path = full_path(uid) blob = storage.get_blob(container.name, path) = nil if = blob[0]. if && (.nil? || .empty?) begin = storage.get_blob(container.name, (path)) = YAML.safe_load([1]) rescue Azure::Core::Http::HTTPError = {} end end end [blob[1], ] rescue Azure::Core::Http::HTTPError nil end |
#url_for(uid, opts = {}) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/dragonfly/azure_data_store.rb', line 61 def url_for(uid, opts = {}) scheme = opts[:scheme] || url_scheme host = opts[:host] || url_host || "#{account_name}.blob.core.windows.net" "#{scheme}://#{host}/#{container_name}/#{full_path(uid)}" end |
#write(content, _opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dragonfly/azure_data_store.rb', line 23 def write(content, _opts = {}) filename = path_for(content.name || 'file') path = full_path(filename) = {} [:metadata] = content. if content.file do |f| storage.create_block_blob(container.name, path, f, ) end filename end |