Class: Stackster::AWS::SimpleDB

Inherits:
Object
  • Object
show all
Defined in:
lib/stackster/aws/simpledb.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ SimpleDB

Returns a new instance of SimpleDB.



7
8
9
10
11
12
# File 'lib/stackster/aws/simpledb.rb', line 7

def initialize(args)
  c = args[:config]
  @connect = Fog::AWS::SimpleDB.new :aws_access_key_id     => c.access_key,
                                    :aws_secret_access_key => c.secret_key,
                                    :region                => c.region
end

Instance Method Details

#create_domain(domain) ⇒ Object



22
23
24
# File 'lib/stackster/aws/simpledb.rb', line 22

def create_domain(domain)
  @connect.create_domain(domain) unless domain_exists?(domain)
end

#delete(domain, key) ⇒ Object



46
47
48
# File 'lib/stackster/aws/simpledb.rb', line 46

def delete(domain, key)
  @connect.delete_attributes domain, key
end

#domain_exists?(domain) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/stackster/aws/simpledb.rb', line 18

def domain_exists?(domain)
  domains.include? domain
end

#domainsObject



14
15
16
# File 'lib/stackster/aws/simpledb.rb', line 14

def domains
  @connect.list_domains.body['Domains']
end

#put_attributes(domain, key, attributes, options) ⇒ Object



26
27
28
# File 'lib/stackster/aws/simpledb.rb', line 26

def put_attributes(domain, key, attributes, options)
  @connect.put_attributes domain, key, attributes, options
end

#select(query) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/stackster/aws/simpledb.rb', line 30

def select(query)
  options = { 'ConsistentRead' => true }
  data = {}
  next_token = nil
  
  while true
    options.merge! 'NextToken' => next_token
    chunk = @connect.select(query, options).body
    data.merge! chunk['Items']
    next_token = chunk['NextToken']
    break unless next_token
  end

  data
end