Class: WAZ::Storage::Base

Inherits:
Object
  • Object
show all
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

Class Method Details

.connected?Boolean

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

Returns:

  • (Boolean)


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_connectionObject

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

Raises:



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(options = {}) # :yields: current_context
   establish_connection!(options)
   if (block_given?)
		  begin 
		    return yield
		  ensure
		    @connections.pop() if connected?
		  end
		end
end

.establish_connection!(options = {}) ⇒ Object

All other parameters are optional.

Raises:



17
18
19
20
21
22
23
24
# File 'lib/waz/storage/base.rb', line 17

def establish_connection!(options = {})
	raise InvalidOption, :account_name unless options.keys.include? :account_name 
	raise InvalidOption, :access_key if !options.keys.include? :use_sas_auth_only unless options.keys.include? :access_key 
		        raise InvalidOption, :use_sas_auth_only if !options.keys.include? :access_key unless options.keys.include? :use_sas_auth_only 
		raise InvalidOption, :sharedaccesssignature if !options.keys.include? :access_key unless options.keys.include? :sharedaccesssignature and options.keys.include? :use_sas_auth_only
		        options[:use_ssl] = false unless options.keys.include? :use_ssl
	(@connections ||= []) << options
end