Class: SimpleDeploy::AWS::SimpleDB

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/simple_deploy/aws/simpledb.rb

Instance Method Summary collapse

Methods included from Helpers

#connection_args

Constructor Details

#initializeSimpleDB

Returns a new instance of SimpleDB.



10
11
12
13
# File 'lib/simple_deploy/aws/simpledb.rb', line 10

def initialize
  @config  = SimpleDeploy.config
  @connect = Fog::AWS::SimpleDB.new connection_args
end

Instance Method Details

#create_domain(domain) ⇒ Object



32
33
34
35
36
# File 'lib/simple_deploy/aws/simpledb.rb', line 32

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

#delete(domain, key) ⇒ Object



62
63
64
65
66
# File 'lib/simple_deploy/aws/simpledb.rb', line 62

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

#delete_items(domain, key, attributes) ⇒ Object



68
69
70
71
72
# File 'lib/simple_deploy/aws/simpledb.rb', line 68

def delete_items(domain, key, attributes)
  with_retries(retry_options) do
    @connect.delete_attributes domain, key, attributes
  end
end

#domain_exists?(domain) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/simple_deploy/aws/simpledb.rb', line 28

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

#domainsObject



22
23
24
25
26
# File 'lib/simple_deploy/aws/simpledb.rb', line 22

def domains
  with_retries(retry_options) do
    @connect.list_domains.body['Domains']
  end
end

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



38
39
40
41
42
# File 'lib/simple_deploy/aws/simpledb.rb', line 38

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

#retry_optionsObject



15
16
17
18
19
20
# File 'lib/simple_deploy/aws/simpledb.rb', line 15

def retry_options
  {:max_retries => 3,
   :rescue => Excon::Errors::ServiceUnavailable,
   :base_sleep_seconds => 10,
   :max_sleep_seconds => 60}
end

#select(query) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/simple_deploy/aws/simpledb.rb', line 44

def select(query)
  options = { 'ConsistentRead' => true }
  data = {}
  next_token = nil

  while true
    options.merge! 'NextToken' => next_token
    chunk = with_retries(retry_options) do
      @connect.select(query, options).body
    end
    data.merge! chunk['Items']
    next_token = chunk['NextToken']
    break unless next_token
  end

  data
end