Class: Heirloom::AWS::SimpleDB
- Inherits:
-
Object
- Object
- Heirloom::AWS::SimpleDB
- Defined in:
- lib/heirloom/aws/simpledb.rb
Instance Method Summary collapse
- #count(domain) ⇒ Object
- #create_domain(domain) ⇒ Object
- #delete(domain, key) ⇒ Object
- #delete_domain(domain) ⇒ Object
- #domain_empty?(domain) ⇒ Boolean
- #domain_exists?(domain) ⇒ Boolean
- #domains ⇒ Object
-
#initialize(args) ⇒ SimpleDB
constructor
A new instance of SimpleDB.
- #item_count(domain, item) ⇒ Object
- #put_attributes(domain, key, attributes, options = {}) ⇒ Object
- #select(query) ⇒ Object
Constructor Details
#initialize(args) ⇒ SimpleDB
Returns a new instance of SimpleDB.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/heirloom/aws/simpledb.rb', line 7 def initialize(args) @config = args[:config] fog_args = { :region => @config. } if @config.use_iam_profile fog_args[:use_iam_profile] = true else fog_args[:aws_access_key_id] = @config.access_key fog_args[:aws_secret_access_key] = @config.secret_key end @sdb = Fog::AWS::SimpleDB.new fog_args end |
Instance Method Details
#count(domain) ⇒ Object
54 55 56 57 |
# File 'lib/heirloom/aws/simpledb.rb', line 54 def count(domain) body = @sdb.select("SELECT count(*) FROM `#{domain}`").body body['Items']['Domain']['Count'].first.to_i end |
#create_domain(domain) ⇒ Object
30 31 32 |
# File 'lib/heirloom/aws/simpledb.rb', line 30 def create_domain(domain) @sdb.create_domain(domain) unless domain_exists?(domain) end |
#delete(domain, key) ⇒ Object
50 51 52 |
# File 'lib/heirloom/aws/simpledb.rb', line 50 def delete(domain, key) @sdb.delete_attributes domain, key end |
#delete_domain(domain) ⇒ Object
34 35 36 |
# File 'lib/heirloom/aws/simpledb.rb', line 34 def delete_domain(domain) @sdb.delete_domain(domain) end |
#domain_empty?(domain) ⇒ Boolean
38 39 40 |
# File 'lib/heirloom/aws/simpledb.rb', line 38 def domain_empty?(domain) count(domain).zero? end |
#domain_exists?(domain) ⇒ Boolean
26 27 28 |
# File 'lib/heirloom/aws/simpledb.rb', line 26 def domain_exists?(domain) domains.include? domain end |
#domains ⇒ Object
22 23 24 |
# File 'lib/heirloom/aws/simpledb.rb', line 22 def domains @sdb.list_domains.body['Domains'] end |
#item_count(domain, item) ⇒ Object
59 60 61 62 |
# File 'lib/heirloom/aws/simpledb.rb', line 59 def item_count(domain, item) query = "SELECT count(*) FROM `#{domain}` WHERE itemName() = '#{item}'" @sdb.select(query).body['Items']['Domain']['Count'].first.to_i end |
#put_attributes(domain, key, attributes, options = {}) ⇒ Object
42 43 44 |
# File 'lib/heirloom/aws/simpledb.rb', line 42 def put_attributes(domain, key, attributes, = {}) @sdb.put_attributes domain, key, attributes, end |
#select(query) ⇒ Object
46 47 48 |
# File 'lib/heirloom/aws/simpledb.rb', line 46 def select(query) @sdb.select(query).body['Items'] end |