Class WAZ::Storage::Base
In: lib/waz/storage/base.rb
Parent: Object

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)


Public Class methods

Returns a value indicating whether the current connection information has been set or not.


    # File lib/waz/storage/base.rb, line 62
62:                                 def connected?
63:                                         return false if (@connections.nil?)
64:                                         return false if (@connections.empty?)
65:                                         return true
66:                                 end

Returns the default connection (last set) parameters. It will raise an exception WAZ::Storage::NotConnected when there‘s no connection information registered.


    # File lib/waz/storage/base.rb, line 56
56:                                 def default_connection
57:           raise NotConnected unless connected?
58:                                         return @connections.last
59:                                 end

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

 The context is restored to the previous one (what you configured on establish_connection!)
 or nil.

Non-Block Syntax

 Behaves exactly as establish_connection!


    # File lib/waz/storage/base.rb, line 43
43:                                 def establish_connection(options = {}) # :yields: current_context
44:                             establish_connection!(options)
45:                             if (block_given?)
46:                                   begin 
47:                                     return yield
48:                                   ensure
49:                                     @connections.pop() if connected?
50:                                   end
51:                                 end
52:                                 end

Sets the basic configuration parameters to use the API on the current context required parameters are :account_name, :access_key.

All other parameters are optional.


    # File lib/waz/storage/base.rb, line 17
17:                                 def establish_connection!(options = {})
18:                                         raise InvalidOption, :account_name unless options.keys.include? :account_name 
19:                                         raise InvalidOption, :access_key if !options.keys.include? :use_sas_auth_only unless options.keys.include? :access_key 
20:                                         raise InvalidOption, :use_sas_auth_only if !options.keys.include? :access_key unless options.keys.include? :use_sas_auth_only 
21:                                         raise InvalidOption, :sharedaccesssignature if !options.keys.include? :access_key unless options.keys.include? :sharedaccesssignature and options.keys.include? :use_sas_auth_only
22:                                         options[:use_ssl] = false unless options.keys.include? :use_ssl
23:                                         (@connections ||= []) << options
24:                                 end