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 AWS
def self.dependencies
[
'fog/aws/ec2.rb',
'fog/aws/simpledb.rb'
'fog/aws/ec2.rb'
]
end

View file

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

View file

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

View file

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

View file

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

View file

@ -1,8 +1,7 @@
unless Fog.mocking?
module Fog
module AWS
class SimpleDB
module SimpleDB
class Real
# Put items attributes into a SimpleDB domain
#
@ -29,27 +28,21 @@ unless Fog.mocking?
end
end
end
end
else
module Fog
module AWS
class SimpleDB
class Mock
def batch_put_attributes(domain_name, items, replace_attributes = Hash.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 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)
Fog::AWS::SimpleDB.data[:domains][domain_name][item_name][key.to_s] = []
@data[:domains][domain_name][item_name][key.to_s] = []
else
Fog::AWS::SimpleDB.data[:domains][domain_name][item_name][key.to_s] ||= []
@data[:domains][domain_name][item_name][key.to_s] ||= []
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
response.status = 200
@ -67,5 +60,4 @@ else
end
end
end
end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,8 +1,9 @@
unless Fog.mocking?
module Fog
module AWS
class SimpleDB
module SimpleDB
class Real
require 'fog/aws/parsers/simpledb/select'
# Select item data from SimpleDB
#
@ -27,14 +28,8 @@ unless Fog.mocking?
end
end
end
end
else
module Fog
module AWS
class SimpleDB
class Mock
def select(select_expression, next_token = nil)
raise MockNotImplemented.new("Contributions welcome!")
@ -43,5 +38,4 @@ else
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 AWS
class SimpleDB
module SimpleDB
def self.new(options={})
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 => {} }
end
def self.data
@data
end
end
def self.dependencies
[
"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?
def initialize(options={})
reset_data
end
end
class Real
# Initialize connection to SimpleDB
#
# ==== Notes
@ -155,5 +152,4 @@ module Fog
end
end
end
Fog::AWS::SimpleDB.reload
end