Class WAZ::Tables::Table
In: lib/waz/tables/table.rb
Parent: Object

This class represents a Table on Windows Azure Tables API. These are the methods implemented from Microsoft‘s API description available on MSDN at msdn.microsoft.com/en-us/library/dd179423.aspx

  # list available tables
  tables = WAZ::Tables::Table.list

  # list more tables
  WAZ::Tables::Table.list(tables.continuation_token)

# get a specific table my_table = WAZ::Tables::Table.find(‘my-table’)

  # delete table
  my_table.destroy!

  # create a new table
  WAZ::Tables::Table.create('new-table')

Methods

create   destroy!   find   list   new   service_instance  

Constants

INVALID_TABLE_ERROR_MESSAGE = "must start with at least one lower/upper characted, can have character or any digit starting from the second position, must be from 3 through 63 characters long"

Attributes

name  [RW] 
url  [RW] 

Public Class methods

Creates a table on the current account.

[Source]

    # File lib/waz/tables/table.rb, line 45
45:         def create(table_name)
46:           raise WAZ::Storage::InvalidParameterValue, {:name => table_name, :values => [INVALID_TABLE_ERROR_MESSAGE]} unless WAZ::Storage::ValidationRules.valid_table_name?(table_name)
47:           WAZ::Tables::Table.new(service_instance.create_table(table_name))
48:         end

Finds a table by name. It will return nil if no table was found.

[Source]

    # File lib/waz/tables/table.rb, line 26
26:         def find(table_name)
27:           raise WAZ::Storage::InvalidParameterValue, {:name => table_name, :values => [INVALID_TABLE_ERROR_MESSAGE]} unless WAZ::Storage::ValidationRules.valid_table_name?(table_name)
28:           begin 
29:             WAZ::Tables::Table.new(service_instance.get_table(table_name))
30:           rescue WAZ::Tables::TableDoesNotExist
31:             return nil
32:           end
33:         end

Returns an array of the existing tables (WAZ::Tables::Table) on the current Windows Azure Storage account.

[Source]

    # File lib/waz/tables/table.rb, line 37
37:         def list(continuation_token = {})
38:             table_list, next_table_name = service_instance.list_tables(continuation_token['NextTableName'])
39:             tables = TableArray.new(table_list.map { |table| WAZ::Tables::Table.new({ :name => table[:name], :url => table[:url] }) })
40:             tables.continuation_token = {'NextTableName' => next_table_name} unless next_table_name.nil?
41:             return tables
42:         end

[Source]

    # File lib/waz/tables/table.rb, line 61
61:       def initialize(options = {})
62:         raise WAZ::Storage::InvalidOption, :name unless options.keys.include?(:name) and !options[:name].empty?
63:         raise WAZ::Storage::InvalidOption, :url unless options.keys.include?(:url) and !options[:url].empty?        
64:         raise WAZ::Storage::InvalidParameterValue, {:name => options[:name], :values => [INVALID_TABLE_ERROR_MESSAGE]} unless WAZ::Storage::ValidationRules.valid_table_name?(options[:name])        
65:         self.name = options[:name]
66:         self.url = options[:url]        
67:       end

This method is internally used by this class. It‘s the way we keep a single instance of the service that wraps the calls the Windows Azure Tables API. It‘s initialized with the values from the default_connection on WAZ::Storage::Base initialized thru establish_connection!

[Source]

    # File lib/waz/tables/table.rb, line 53
53:         def service_instance
54:           options = WAZ::Storage::Base.default_connection.merge(:type_of_service => "table")
55:           (@service_instances ||= {})[options[:account_name]] ||= Service.new(options)
56:         end

Public Instance methods

Removes the table from the current account.

[Source]

    # File lib/waz/tables/table.rb, line 70
70:       def destroy!
71:         self.class.service_instance.delete_table(self.name)
72:       end

[Validate]