module RD3::DataProviders::AzureTableStorage

Public Class Methods

_logical_only(opts) click to toggle source
# File lib/rd3/data_providers/azure_table_storage.rb, line 56
def self._logical_only(opts)
  unless opts[:logical_only].nil?
    opts[:logical_only]
  else
    RD3.config.enable_logical_deletes
  end
end
client() click to toggle source
# File lib/rd3/data_providers/azure_table_storage.rb, line 11
def self.client
  return @client if @client

  yml_config = YAML.load(File.read("#{RD3.config.config_file_directory}/#{self.config_file_name}.yml"))[RD3.config.environment.to_s]
  yml_config = yml_config.symbolize_keys

  WAZ::Storage::Base.establish_connection!(:account_name => yml_config[:storage_account_name],
                                           :access_key => yml_config[:primary_access_key])
  @client = WAZ::Tables::Table.service_instance
end
delete(key, opts={}) click to toggle source
# File lib/rd3/data_providers/azure_table_storage.rb, line 45
def self.delete(key, opts={})
  if self._logical_only(opts)
    attributes= {:partition_key => key,
                 :row_key => opts[:row_key],
                 :active => false}
    @client.update_entity(self.table_name.to_s, attributes)
  else
    @client.delete_entity(self.table_name.to_s, key, opts[:row_key])
  end
end
find_by_key(key, opts={}) click to toggle source
# File lib/rd3/data_providers/azure_table_storage.rb, line 36
def self.find_by_key(key, opts={})
  begin
    if db_instance = @client.get_entity(self.table_name.to_s, key, opts[:row_key])
      db_instance unless self._logical_only(opts) && !db_instance[:active]
    end
  rescue RestClient::ResourceNotFound # returns nil
  end
end
save(attributes) click to toggle source
# File lib/rd3/data_providers/azure_table_storage.rb, line 22
def self.save(attributes)
  # convert the key attribute to partition key
  # NOTE: don't overwrite the partion key if it has already been set
  attributes[:partition_key] ||= partition_key = attributes.delete(:key)

  unless attributes[:Timestamp]
    self.client.insert_entity(self.table_name.to_s, attributes)
  else
    self.client.update_entity(self.table_name.to_s, attributes)
  end

  partition_key
end