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)


60
61
62
63
64
# File 'lib/waz/storage/base.rb', line 60

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:



54
55
56
57
# File 'lib/waz/storage/base.rb', line 54

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!


41
42
43
44
45
46
47
48
49
50
# File 'lib/waz/storage/base.rb', line 41

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
# 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 unless options.keys.include? :access_key
	options[:use_ssl] = false unless options.keys.include? :use_ssl
	(@connections ||= []) << options
end