Class: RAWS::SDB

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/raws/sdb.rb

Defined Under Namespace

Modules: Model Classes: Adapter, Select

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain_name) ⇒ SDB

Returns a new instance of SDB.



100
101
102
# File 'lib/raws/sdb.rb', line 100

def initialize(domain_name)
  @domain_name = domain_name
end

Class Attribute Details

.httpObject



11
12
13
# File 'lib/raws/sdb.rb', line 11

def http
  @http ||= RAWS.http
end

Instance Attribute Details

#domain_nameObject (readonly)

Returns the value of attribute domain_name.



98
99
100
# File 'lib/raws/sdb.rb', line 98

def domain_name
  @domain_name
end

Class Method Details

.[](domain_name) ⇒ Object

Returns the instance of RAWS::SDB.



59
60
61
# File 'lib/raws/sdb.rb', line 59

def [](domain_name)
  self.new domain_name
end

.allObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/raws/sdb.rb', line 73

def select(expr, params=[], &block)
  next_token = nil
  begin
    ret = Adapter.select(expr, params, next_token)\
      ['SelectResponse']['SelectResult']
    ret['Item'].each do |val|
      block.call [val['Name'], val['Attribute']]
    end if ret
  end while ret && next_token = ret['NextToken']
end

.batch_putObject



90
91
92
# File 'lib/raws/sdb.rb', line 90

def batch_put_attributes(domain_name, items={}, replaces={})
  Adapter.batch_put_attributes domain_name, items, replaces
end

.batch_put_attributes(domain_name, items = {}, replaces = {}) ⇒ Object



87
88
89
# File 'lib/raws/sdb.rb', line 87

def batch_put_attributes(domain_name, items={}, replaces={})
  Adapter.batch_put_attributes domain_name, items, replaces
end

.create_domain(domain_name) ⇒ Object

Creates a new domain and returns the instance of RAWS:SDB.



16
17
18
19
# File 'lib/raws/sdb.rb', line 16

def create_domain(domain_name)
  Adapter.create_domain(domain_name)
  self[domain_name]
end

.deleteObject



95
96
97
# File 'lib/raws/sdb.rb', line 95

def delete_attributes(domain_name, item_name, attrs={})
  Adapter.delete_attributes domain_name, item_name, attrs
end

.delete_attributes(domain_name, item_name, attrs = {}) ⇒ Object



92
93
94
# File 'lib/raws/sdb.rb', line 92

def delete_attributes(domain_name, item_name, attrs={})
  Adapter.delete_attributes domain_name, item_name, attrs
end

.delete_domain(domain_name) ⇒ Object

Deletes the domain.



22
23
24
# File 'lib/raws/sdb.rb', line 22

def delete_domain(domain_name)
  Adapter.delete_domain(domain_name)
end

.domain_metadata(domain_name) ⇒ Object

Returns the domain metadata.



27
28
29
30
# File 'lib/raws/sdb.rb', line 27

def (domain_name)
  Adapter.(domain_name)\
    ['DomainMetadataResponse']['DomainMetadataResult']
end

.domains(&block) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/raws/sdb.rb', line 50

def domains(&block)
  if block_given?
    each(&block)
  else
    map
  end
end

.each(params = {}, &block) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/raws/sdb.rb', line 42

def each(params={}, &block)
  next_token = nil
  begin
    data = list_domains(params.merge('NextToken' => next_token))
    data['Domains'].each(&block)
  end while next_token = data['NextToken']
end

.getObject



80
81
82
83
84
# File 'lib/raws/sdb.rb', line 80

def get_attributes(domain_name, item_name, *attrs)
  doc = Adapter.get_attributes(domain_name, item_name, *attrs)\
    ['GetAttributesResponse']['GetAttributesResult']
  doc && doc['Attribute']
end

.get_attributes(domain_name, item_name, *attrs) ⇒ Object



75
76
77
78
79
# File 'lib/raws/sdb.rb', line 75

def get_attributes(domain_name, item_name, *attrs)
  doc = Adapter.get_attributes(domain_name, item_name, *attrs)\
    ['GetAttributesResponse']['GetAttributesResult']
  doc && doc['Attribute']
end

.list_domains(params = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/raws/sdb.rb', line 32

def list_domains(params={})
  doc = Adapter.list_domains(params)\
    ['ListDomainsResponse']['ListDomainsResult']

  {
    'Domains' => (doc ? doc['DomainName'] : []).map do |v| self.new(v) end,
    'NextToken' => doc && doc['NextToken']
  }
end

.putObject



85
86
87
# File 'lib/raws/sdb.rb', line 85

def put_attributes(domain_name, item_name, attrs={}, *replaces)
  Adapter.put_attributes domain_name, item_name, attrs, *replaces
end

.put_attributes(domain_name, item_name, attrs = {}, *replaces) ⇒ Object



82
83
84
# File 'lib/raws/sdb.rb', line 82

def put_attributes(domain_name, item_name, attrs={}, *replaces)
  Adapter.put_attributes domain_name, item_name, attrs, *replaces
end

.select(expr, params = [], &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/raws/sdb.rb', line 63

def select(expr, params=[], &block)
  next_token = nil
  begin
    ret = Adapter.select(expr, params, next_token)\
      ['SelectResponse']['SelectResult']
    ret['Item'].each do |val|
      block.call [val['Name'], val['Attribute']]
    end if ret
  end while ret && next_token = ret['NextToken']
end

Instance Method Details

#<=>(a) ⇒ Object



142
143
144
# File 'lib/raws/sdb.rb', line 142

def <=>(a)
  domain_name <=> a.domain_name
end

#batch_put_attributes(items, replaces = {}) ⇒ Object Also known as: batch_put



132
133
134
# File 'lib/raws/sdb.rb', line 132

def batch_put_attributes(items, replaces={})
  self.class.batch_put_attributes domain_name, items, replaces
end

#create_domainObject



104
105
106
# File 'lib/raws/sdb.rb', line 104

def create_domain
  self.class.create_domain(domain_name)
end

#delete_attributes(item_name, attrs = {}) ⇒ Object Also known as: delete



137
138
139
# File 'lib/raws/sdb.rb', line 137

def delete_attributes(item_name, attrs={})
  self.class.delete_attributes domain_name, item_name, attrs
end

#delete_domainObject



108
109
110
# File 'lib/raws/sdb.rb', line 108

def delete_domain
  self.class.delete_domain(domain_name)
end

#domain_metadataObject Also known as: metadata



112
113
114
# File 'lib/raws/sdb.rb', line 112

def 
  self.class.(domain_name)
end

#get_attributes(item_name, *attrs) ⇒ Object Also known as: get



122
123
124
# File 'lib/raws/sdb.rb', line 122

def get_attributes(item_name, *attrs)
  self.class.get_attributes domain_name, item_name, *attrs
end

#put_attributes(item_name, attrs, *replaces) ⇒ Object Also known as: put



127
128
129
# File 'lib/raws/sdb.rb', line 127

def put_attributes(item_name, attrs, *replaces)
  self.class.put_attributes domain_name, item_name, attrs, *replaces
end

#select(output_list = '*', &block) ⇒ Object Also known as: all



117
118
119
# File 'lib/raws/sdb.rb', line 117

def select(output_list='*', &block)
  Select.new.columns(output_list).from(domain_name, &block)
end