Class: WAZ::Storage::Base
- Inherits:
-
Object
- Object
- WAZ::Storage::Base
- Defined in:
- lib/waz/storage/base.rb
Overview
This class is used to handle a general connection with Windows Azure Storage Account and it should be used at least once on the application bootstrap or configuration file.
The usage is pretty simple as it’s depicted on the following sample
WAZ::Storage::establish_connection!(:account_name => "my_account_name",
:access_key => "your_base64_key",
:use_ssl => false)
Class Method Summary collapse
-
.connected? ⇒ Boolean
Returns a value indicating whether the current connection information has been set or not.
-
.default_connection ⇒ Object
Returns the default connection (last set) parameters.
-
.establish_connection(options = {}) ⇒ Object
Block Syntax.
-
.establish_connection!(options = {}) ⇒ Object
All other parameters are optional.
Class Method Details
.connected? ⇒ Boolean
Returns a value indicating whether the current connection information has been set or not.
62 63 64 65 66 |
# File 'lib/waz/storage/base.rb', line 62 def connected? return false if (@connections.nil?) return false if (@connections.empty?) return true end |
.default_connection ⇒ Object
Returns the default connection (last set) parameters. It will raise an exception WAZ::Storage::NotConnected when there’s no connection information registered.
56 57 58 59 |
# File 'lib/waz/storage/base.rb', line 56 def default_connection raise NotConnected unless connected? return @connections.last end |
.establish_connection(options = {}) ⇒ Object
Block Syntax
Pushes the named repository onto the context-stack,
yields a new session, and pops the context-stack.
This helps you set contextual operations like in the following sample
Base.establish_connection(options) do
# do some operations on the given context
end
The context is restored to the previous one (what you configured on establish_connection!)
or nil.
Non-Block Syntax
Behaves exactly as establish_connection!
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/waz/storage/base.rb', line 43 def establish_connection( = {}) # :yields: current_context establish_connection!() if (block_given?) begin return yield ensure @connections.pop() if connected? end end end |
.establish_connection!(options = {}) ⇒ Object
All other parameters are optional.
17 18 19 20 21 22 23 24 |
# File 'lib/waz/storage/base.rb', line 17 def establish_connection!( = {}) raise InvalidOption, :account_name unless .keys.include? :account_name raise InvalidOption, :access_key if !.keys.include? :use_sas_auth_only unless .keys.include? :access_key raise InvalidOption, :use_sas_auth_only if !.keys.include? :access_key unless .keys.include? :use_sas_auth_only raise InvalidOption, :sharedaccesssignature if !.keys.include? :access_key unless .keys.include? :sharedaccesssignature and .keys.include? :use_sas_auth_only [:use_ssl] = false unless .keys.include? :use_ssl (@connections ||= []) << end |