Class: WAZ::Tables::Table
- Inherits:
-
Object
- Object
- WAZ::Tables::Table
- Defined in:
- lib/waz/tables/table.rb
Overview
# delete table my_table.destroy!
# create a new table WAZ::Tables::Table.create(‘new-table’)
Constant Summary collapse
- 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"
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.create(table_name) ⇒ Object
Creates a table on the current account.
-
.find(table_name) ⇒ Object
Finds a table by name.
-
.list(continuation_token = {}) ⇒ Object
Returns an array of the existing tables (WAZ::Tables::Table) on the current Windows Azure Storage account.
-
.service_instance ⇒ Object
This method is internally used by this class.
Instance Method Summary collapse
-
#destroy! ⇒ Object
Removes the table from the current account.
-
#initialize(options = {}) ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize(options = {}) ⇒ Table
Returns a new instance of Table.
61 62 63 64 65 66 67 |
# File 'lib/waz/tables/table.rb', line 61 def initialize( = {}) raise WAZ::Storage::InvalidOption, :name unless .keys.include?(:name) and ![:name].empty? raise WAZ::Storage::InvalidOption, :url unless .keys.include?(:url) and ![:url].empty? raise WAZ::Storage::InvalidParameterValue, {:name => [:name], :values => [INVALID_TABLE_ERROR_MESSAGE]} unless WAZ::Storage::ValidationRules.valid_table_name?([:name]) self.name = [:name] self.url = [:url] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
59 60 61 |
# File 'lib/waz/tables/table.rb', line 59 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
59 60 61 |
# File 'lib/waz/tables/table.rb', line 59 def url @url end |
Class Method Details
.create(table_name) ⇒ Object
Creates a table on the current account.
45 46 47 48 |
# File 'lib/waz/tables/table.rb', line 45 def create(table_name) raise WAZ::Storage::InvalidParameterValue, {:name => table_name, :values => [INVALID_TABLE_ERROR_MESSAGE]} unless WAZ::Storage::ValidationRules.valid_table_name?(table_name) WAZ::Tables::Table.new(service_instance.create_table(table_name)) end |
.find(table_name) ⇒ Object
Finds a table by name. It will return nil if no table was found.
26 27 28 29 30 31 32 33 |
# File 'lib/waz/tables/table.rb', line 26 def find(table_name) raise WAZ::Storage::InvalidParameterValue, {:name => table_name, :values => [INVALID_TABLE_ERROR_MESSAGE]} unless WAZ::Storage::ValidationRules.valid_table_name?(table_name) begin WAZ::Tables::Table.new(service_instance.get_table(table_name)) rescue WAZ::Tables::TableDoesNotExist return nil end end |
.list(continuation_token = {}) ⇒ Object
Returns an array of the existing tables (WAZ::Tables::Table) on the current Windows Azure Storage account.
37 38 39 40 41 42 |
# File 'lib/waz/tables/table.rb', line 37 def list(continuation_token = {}) table_list, next_table_name = service_instance.list_tables(continuation_token['NextTableName']) tables = TableArray.new(table_list.map { |table| WAZ::Tables::Table.new({ :name => table[:name], :url => table[:url] }) }) tables.continuation_token = {'NextTableName' => next_table_name} unless next_table_name.nil? return tables end |
.service_instance ⇒ Object
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!
53 54 55 56 |
# File 'lib/waz/tables/table.rb', line 53 def service_instance = WAZ::Storage::Base.default_connection.merge(:type_of_service => "table") (@service_instances ||= {})[[:account_name]] ||= Service.new() end |
Instance Method Details
#destroy! ⇒ Object
Removes the table from the current account.
70 71 72 |
# File 'lib/waz/tables/table.rb', line 70 def destroy! self.class.service_instance.delete_table(self.name) end |