Class: AWS::SimpleDB::DomainCollection

Inherits:
Object
  • Object
show all
Includes:
Core::Model, Enumerable
Defined in:
lib/aws/simple_db/domain_collection.rb

Overview

An Enumerable collection representing all your domains in SimpleDB.

Use a DomainCollection to create, get and list domains.

Examples:

Creating a domain in SimpleDB


sdb = SimpleDB.new
domain = sdb.domains.create('mydomain')

Getting a domain with indifferent access


domain = sdb.domains[:mydomain]
domain = sdb.domains['mydomain']

Enumerating domains


sdb.domains.each do |domain|
  puts domain.name
end

Instance Attribute Summary

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from Core::Model

#client, #config_prefix, #initialize, #inspect

Instance Method Details

#[](domain_name) ⇒ Domain

Note:

This does not attempt to create the domain if it does not already exist in SimpleDB. Use #create to add a domain to SDB.

Returns a domain object with the given name.

Parameters:

  • domain_name (String)

    The name of the domain to return.

Returns:

  • (Domain)

    Returns the domain with the given name.


63
64
65
# File 'lib/aws/simple_db/domain_collection.rb', line 63

def [] domain_name
  domain_named(domain_name)
end

#create(domain_name) ⇒ Domain

Note:

This operation might take 10 or more seconds to complete.

Note:

Creating a domain in SimpleDB is an idempotent operation; running it multiple times using the same domain name will not result in an error.

Note:

You can create up to 100 domains per account.

Creates a domain in SimpleDB and returns a domain object.

Parameters:

  • domain_name (String)

Returns:

  • (Domain)

    Returns a new domain with the given name.


51
52
53
54
# File 'lib/aws/simple_db/domain_collection.rb', line 51

def create(domain_name)
  client.create_domain(:domain_name => domain_name)
  domain_named(domain_name)
end

#each(options = {}) {|domain| ... } ⇒ nil

Note:

Normally your account has a limit of 100 SimpleDB domains. You can request more here

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :limit (Integer) — default: nil

    The maximum number of domains to yield.

  • :batch_size (Integer) — default: 100

    The number of domains to fetch each request to SimpleDB. Maximum is 100.

Yields:

  • (domain)

    Yields once for every domain in your account.

Yield Parameters:

Returns:

  • (nil)

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/aws/simple_db/domain_collection.rb', line 76

def each options = {}, &block

  total_limit = options[:limit]
  batch_size = options[:batch_size] || 100
  received = 0
  next_token = nil

  begin

    limit = total_limit ? 
      [total_limit - received, batch_size].min : 
      batch_size

    list_options = { :max_number_of_domains => limit }
    list_options[:next_token] = next_token if next_token
    list = client.list_domains(list_options)

    next_token = list[:next_token]
    received += list[:domain_names].size

    list[:domain_names].each do |name|
      yield(domain_named(name))
    end
  
  end while next_token and (total_limit.nil? or received < total_limit)
  nil
end