1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[simpledb] cleaner mocking/dependencies

This commit is contained in:
geemus (Wesley Beary) 2010-03-14 20:11:43 -07:00
parent 46ea4a4a99
commit 293811ad42
15 changed files with 212 additions and 271 deletions

View file

@ -1,12 +1,12 @@
require 'fog/aws/s3.rb' require 'fog/aws/s3'
require 'fog/aws/simpledb'
module Fog module Fog
module AWS module AWS
def self.dependencies def self.dependencies
[ [
'fog/aws/ec2.rb', 'fog/aws/ec2.rb'
'fog/aws/simpledb.rb'
] ]
end end

View file

@ -1,3 +1,5 @@
require 'fog/aws/parsers/simpledb/basic'
module Fog module Fog
module Parsers module Parsers
module AWS module AWS

View file

@ -1,3 +1,5 @@
require 'fog/aws/parsers/simpledb/basic'
module Fog module Fog
module Parsers module Parsers
module AWS module AWS

View file

@ -1,3 +1,5 @@
require 'fog/aws/parsers/simpledb/basic'
module Fog module Fog
module Parsers module Parsers
module AWS module AWS

View file

@ -1,3 +1,5 @@
require 'fog/aws/parsers/simpledb/basic'
module Fog module Fog
module Parsers module Parsers
module AWS module AWS

View file

@ -1,8 +1,7 @@
unless Fog.mocking?
module Fog module Fog
module AWS module AWS
class SimpleDB module SimpleDB
class Real
# Put items attributes into a SimpleDB domain # Put items attributes into a SimpleDB domain
# #
@ -29,27 +28,21 @@ unless Fog.mocking?
end end
end end
end
end
else class Mock
module Fog
module AWS
class SimpleDB
def batch_put_attributes(domain_name, items, replace_attributes = Hash.new([])) def batch_put_attributes(domain_name, items, replace_attributes = Hash.new([]))
response = Excon::Response.new response = Excon::Response.new
if Fog::AWS::SimpleDB.data[:domains][domain_name] if @data[:domains][domain_name]
for item_name, attributes in items do for item_name, attributes in items do
for key, value in attributes do for key, value in attributes do
Fog::AWS::SimpleDB.data[:domains][domain_name][item_name] ||= {} @data[:domains][domain_name][item_name] ||= {}
if replace_attributes[item_name] && replace_attributes[item_name].include?(key) if replace_attributes[item_name] && replace_attributes[item_name].include?(key)
Fog::AWS::SimpleDB.data[:domains][domain_name][item_name][key.to_s] = [] @data[:domains][domain_name][item_name][key.to_s] = []
else else
Fog::AWS::SimpleDB.data[:domains][domain_name][item_name][key.to_s] ||= [] @data[:domains][domain_name][item_name][key.to_s] ||= []
end end
Fog::AWS::SimpleDB.data[:domains][domain_name][item_name][key.to_s] << value.to_s @data[:domains][domain_name][item_name][key.to_s] << value.to_s
end end
end end
response.status = 200 response.status = 200
@ -67,5 +60,4 @@ else
end end
end end
end end
end end

View file

@ -1,8 +1,7 @@
unless Fog.mocking?
module Fog module Fog
module AWS module AWS
class SimpleDB module SimpleDB
class Real
# Create a SimpleDB domain # Create a SimpleDB domain
# #
@ -23,18 +22,12 @@ unless Fog.mocking?
end end
end end
end
end
else class Mock
module Fog
module AWS
class SimpleDB
def create_domain(domain_name) def create_domain(domain_name)
response = Excon::Response.new response = Excon::Response.new
Fog::AWS::SimpleDB.data[:domains][domain_name] = {} @data[:domains][domain_name] = {}
response.status = 200 response.status = 200
response.body = { response.body = {
'BoxUsage' => Fog::AWS::Mock.box_usage, 'BoxUsage' => Fog::AWS::Mock.box_usage,
@ -46,5 +39,4 @@ else
end end
end end
end end
end end

View file

@ -1,8 +1,7 @@
unless Fog.mocking?
module Fog module Fog
module AWS module AWS
class SimpleDB module SimpleDB
class Real
# List metadata for SimpleDB domain # List metadata for SimpleDB domain
# #
@ -32,26 +31,20 @@ unless Fog.mocking?
end end
end end
end
end
else class Mock
module Fog
module AWS
class SimpleDB
def delete_attributes(domain_name, item_name, attributes = nil) def delete_attributes(domain_name, item_name, attributes = nil)
response = Excon::Response.new response = Excon::Response.new
if Fog::AWS::SimpleDB.data[:domains][domain_name] if @data[:domains][domain_name]
if attributes if attributes
for key, value in attributes for key, value in attributes
if Fog::AWS::SimpleDB.data[:domains][domain_name][key] if @data[:domains][domain_name][key]
Fog::AWS::SimpleDB.data[:domains][domain_name][key].delete('value') @data[:domains][domain_name][key].delete('value')
end end
end end
else else
Fog::AWS::SimpleDB.data[:domains].delete(domain_name) @data[:domains].delete(domain_name)
end end
response.status = 200 response.status = 200
response.body = { response.body = {
@ -68,5 +61,4 @@ else
end end
end end
end end
end end

View file

@ -1,8 +1,7 @@
unless Fog.mocking?
module Fog module Fog
module AWS module AWS
class SimpleDB module SimpleDB
class Real
# Delete a SimpleDB domain # Delete a SimpleDB domain
# #
@ -23,18 +22,12 @@ unless Fog.mocking?
end end
end end
end
end
else class Mock
module Fog
module AWS
class SimpleDB
def delete_domain(domain_name) def delete_domain(domain_name)
response = Excon::Response.new response = Excon::Response.new
if Fog::AWS::SimpleDB.data[:domains].delete(domain_name) if @data[:domains].delete(domain_name)
response.status = 200 response.status = 200
response.body = { response.body = {
'BoxUsage' => Fog::AWS::Mock.box_usage, 'BoxUsage' => Fog::AWS::Mock.box_usage,
@ -47,5 +40,4 @@ else
end end
end end
end end
end end

View file

@ -1,8 +1,9 @@
unless Fog.mocking?
module Fog module Fog
module AWS module AWS
class SimpleDB module SimpleDB
class Real
require 'fog/aws/parsers/simpledb/domain_metadata'
# List metadata for SimpleDB domain # List metadata for SimpleDB domain
# #
@ -30,18 +31,12 @@ unless Fog.mocking?
end end
end end
end
end
else class Mock
module Fog
module AWS
class SimpleDB
def domain_metadata(domain_name) def domain_metadata(domain_name)
response = Excon::Response.new response = Excon::Response.new
if domain = Fog::AWS::SimpleDB.data[:domains][domain_name] if domain = @data[:domains][domain_name]
response.status = 200 response.status = 200
attribute_names = [] attribute_names = []
@ -76,5 +71,4 @@ else
end end
end end
end end
end end

View file

@ -1,8 +1,9 @@
unless Fog.mocking?
module Fog module Fog
module AWS module AWS
class SimpleDB module SimpleDB
class Real
require 'fog/aws/parsers/simpledb/get_attributes'
# List metadata for SimpleDB domain # List metadata for SimpleDB domain
# #
@ -13,7 +14,7 @@ unless Fog.mocking?
# in xml. Control characters and sequences not allowed in xml are not # in xml. Control characters and sequences not allowed in xml are not
# valid. Can be up to 1024 bytes long. # valid. Can be up to 1024 bytes long.
# * attributes<~Array> - Attributes to return from the item. Defaults to # * attributes<~Array> - Attributes to return from the item. Defaults to
# nil, which will return all attributes. Attribute names and values may use # {}, which will return all attributes. Attribute names and values may use
# any UTF-8 characters valid in xml. Control characters and sequences not # any UTF-8 characters valid in xml. Control characters and sequences not
# allowed in xml are not valid. Each name and value can be up to 1024 # allowed in xml are not valid. Each name and value can be up to 1024
# bytes long. # bytes long.
@ -24,7 +25,8 @@ unless Fog.mocking?
# * 'Attributes' - list of attribute name/values for the item # * 'Attributes' - list of attribute name/values for the item
# * 'BoxUsage' # * 'BoxUsage'
# * 'RequestId' # * 'RequestId'
def get_attributes(domain_name, item_name, attributes = nil) def get_attributes(domain_name, item_name, attributes = {})
request({ request({
'Action' => 'GetAttributes', 'Action' => 'GetAttributes',
'DomainName' => domain_name, 'DomainName' => domain_name,
@ -33,27 +35,21 @@ unless Fog.mocking?
end end
end end
end
end
else class Mock
module Fog
module AWS
class SimpleDB
def get_attributes(domain_name, item_name, attributes = nil) def get_attributes(domain_name, item_name, attributes = nil)
response = Excon::Response.new response = Excon::Response.new
if Fog::AWS::SimpleDB.data[:domains][domain_name] if @data[:domains][domain_name]
object = {} object = {}
if attributes if attributes
for attribute in attributes for attribute in attributes
if Fog::AWS::SimpleDB.data[:domains][domain_name][item_name] && Fog::AWS::SimpleDB.data[:domains][domain_name][item_name] if @data[:domains][domain_name][item_name] && @data[:domains][domain_name][item_name]
object[attribute] = Fog::AWS::SimpleDB.data[:domains][domain_name][item_name][attribute] object[attribute] = @data[:domains][domain_name][item_name][attribute]
end end
end end
elsif Fog::AWS::SimpleDB.data[:domains][domain_name][item_name] elsif @data[:domains][domain_name][item_name]
object = Fog::AWS::SimpleDB.data[:domains][domain_name][item_name] object = @data[:domains][domain_name][item_name]
end end
response.status = 200 response.status = 200
response.body = { response.body = {
@ -71,5 +67,4 @@ else
end end
end end
end end
end end

View file

@ -1,8 +1,9 @@
unless Fog.mocking?
module Fog module Fog
module AWS module AWS
class SimpleDB module SimpleDB
class Real
require 'fog/aws/parsers/simpledb/list_domains'
# List SimpleDB domains # List SimpleDB domains
# #
@ -26,22 +27,16 @@ unless Fog.mocking?
end end
end end
end
end
else class Mock
module Fog
module AWS
class SimpleDB
def list_domains(options = {}) def list_domains(options = {})
response = Excon::Response.new response = Excon::Response.new
keys = Fog::AWS::SimpleDB.data[:domains].keys keys = @data[:domains].keys
max = options['MaxNumberOfDomains'] || keys.size max = options['MaxNumberOfDomains'] || keys.size
offset = options['NextToken'] || 0 offset = options['NextToken'] || 0
domains = [] domains = []
for key, value in Fog::AWS::SimpleDB.data[:domains].keys[offset...max] for key, value in @data[:domains].keys[offset...max]
domains << key domains << key
end end
response.status = 200 response.status = 200
@ -59,5 +54,4 @@ else
end end
end end
end end
end end

View file

@ -1,8 +1,7 @@
unless Fog.mocking?
module Fog module Fog
module AWS module AWS
class SimpleDB module SimpleDB
class Real
# Put item attributes into a SimpleDB domain # Put item attributes into a SimpleDB domain
# #
@ -27,14 +26,8 @@ unless Fog.mocking?
end end
end end
end
end
else class Mock
module Fog
module AWS
class SimpleDb
def put_attributes(domain_name, item_name, attributes, replace_attributes = []) def put_attributes(domain_name, item_name, attributes, replace_attributes = [])
batch_put_attributes(domain_name, { item_name => attributes }, { item_name => replace_attributes }) batch_put_attributes(domain_name, { item_name => attributes }, { item_name => replace_attributes })
@ -43,5 +36,4 @@ else
end end
end end
end end
end end

View file

@ -1,8 +1,9 @@
unless Fog.mocking?
module Fog module Fog
module AWS module AWS
class SimpleDB module SimpleDB
class Real
require 'fog/aws/parsers/simpledb/select'
# Select item data from SimpleDB # Select item data from SimpleDB
# #
@ -27,14 +28,8 @@ unless Fog.mocking?
end end
end end
end
end
else class Mock
module Fog
module AWS
class SimpleDB
def select(select_expression, next_token = nil) def select(select_expression, next_token = nil)
raise MockNotImplemented.new("Contributions welcome!") raise MockNotImplemented.new("Contributions welcome!")
@ -43,5 +38,4 @@ else
end end
end end
end end
end end

View file

@ -1,42 +1,39 @@
require 'fog/aws/requests/simpledb/batch_put_attributes'
require 'fog/aws/requests/simpledb/create_domain'
require 'fog/aws/requests/simpledb/delete_attributes'
require 'fog/aws/requests/simpledb/delete_domain'
require 'fog/aws/requests/simpledb/domain_metadata'
require 'fog/aws/requests/simpledb/get_attributes'
require 'fog/aws/requests/simpledb/list_domains'
require 'fog/aws/requests/simpledb/put_attributes'
require 'fog/aws/requests/simpledb/select'
module Fog module Fog
module AWS module AWS
class SimpleDB module SimpleDB
def self.new(options={})
if Fog.mocking? if Fog.mocking?
def self.reset_data Fog::AWS::SimpleDB::Mock.new(options)
else
Fog::AWS::SimpleDB::Real.new(options)
end
end
class Mock
def reset_data
@data = { :domains => {} } @data = { :domains => {} }
end end
def self.data
@data
end
end
def self.dependencies def initialize(options={})
[
"fog/aws/parsers/simpledb/basic.rb",
"fog/aws/parsers/simpledb/domain_metadata.rb",
"fog/aws/parsers/simpledb/get_attributes.rb",
"fog/aws/parsers/simpledb/list_domains.rb",
"fog/aws/parsers/simpledb/select.rb",
"fog/aws/requests/simpledb/batch_put_attributes.rb",
"fog/aws/requests/simpledb/create_domain.rb",
"fog/aws/requests/simpledb/delete_attributes.rb",
"fog/aws/requests/simpledb/delete_domain.rb",
"fog/aws/requests/simpledb/domain_metadata.rb",
"fog/aws/requests/simpledb/get_attributes.rb",
"fog/aws/requests/simpledb/list_domains.rb",
"fog/aws/requests/simpledb/put_attributes.rb",
"fog/aws/requests/simpledb/select.rb"
]
end
def self.reload
self.dependencies.each {|dependency| load(dependency)}
if Fog.mocking?
reset_data reset_data
end end
end end
class Real
# Initialize connection to SimpleDB # Initialize connection to SimpleDB
# #
# ==== Notes # ==== Notes
@ -155,5 +152,4 @@ module Fog
end end
end end
end end
end
Fog::AWS::SimpleDB.reload