Class: Fog::AWS::SimpleDB::Mock
- Inherits:
-
Object
- Object
- Fog::AWS::SimpleDB::Mock
- Defined in:
- lib/fog/aws/simpledb.rb,
lib/fog/aws/requests/simpledb/select.rb,
lib/fog/aws/requests/simpledb/list_domains.rb,
lib/fog/aws/requests/simpledb/create_domain.rb,
lib/fog/aws/requests/simpledb/delete_domain.rb,
lib/fog/aws/requests/simpledb/get_attributes.rb,
lib/fog/aws/requests/simpledb/put_attributes.rb,
lib/fog/aws/requests/simpledb/domain_metadata.rb,
lib/fog/aws/requests/simpledb/delete_attributes.rb,
lib/fog/aws/requests/simpledb/batch_put_attributes.rb
Class Method Summary collapse
Instance Method Summary collapse
- #batch_put_attributes(domain_name, items, replace_attributes = Hash.new([])) ⇒ Object
- #create_domain(domain_name) ⇒ Object
- #delete_attributes(domain_name, item_name, attributes = nil) ⇒ Object
- #delete_domain(domain_name) ⇒ Object
- #domain_metadata(domain_name) ⇒ Object
- #get_attributes(domain_name, item_name, attributes = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_domains(options = {}) ⇒ Object
- #put_attributes(domain_name, item_name, attributes, options = {}) ⇒ Object
- #select(select_expression, next_token = nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
35 36 37 38 |
# File 'lib/fog/aws/simpledb.rb', line 35 def initialize(={}) @aws_access_key_id = [:aws_access_key_id] @data = self.class.data[@aws_access_key_id] end |
Class Method Details
.data ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/fog/aws/simpledb.rb', line 21 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :domains => {} } end end |
.reset_data(keys = data.keys) ⇒ Object
29 30 31 32 33 |
# File 'lib/fog/aws/simpledb.rb', line 29 def self.reset_data(keys=data.keys) for key in [*keys] data.delete(key) end end |
Instance Method Details
#batch_put_attributes(domain_name, items, replace_attributes = Hash.new([])) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fog/aws/requests/simpledb/batch_put_attributes.rb', line 35 def batch_put_attributes(domain_name, items, replace_attributes = Hash.new([])) response = Excon::Response.new if @data[:domains][domain_name] for item_name, attributes in items do for key, value in attributes do @data[:domains][domain_name][item_name] ||= {} if replace_attributes[item_name] && replace_attributes[item_name].include?(key) @data[:domains][domain_name][item_name][key.to_s] = [] else @data[:domains][domain_name][item_name][key.to_s] ||= [] end @data[:domains][domain_name][item_name][key.to_s] << value.to_s end end response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#create_domain(domain_name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/aws/requests/simpledb/create_domain.rb', line 30 def create_domain(domain_name) response = Excon::Response.new @data[:domains][domain_name] = {} response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } response end |
#delete_attributes(domain_name, item_name, attributes = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fog/aws/requests/simpledb/delete_attributes.rb', line 38 def delete_attributes(domain_name, item_name, attributes = nil) response = Excon::Response.new if @data[:domains][domain_name] if attributes for key, value in attributes if @data[:domains][domain_name][key] @data[:domains][domain_name][key].delete('value') end end end response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#delete_domain(domain_name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/aws/requests/simpledb/delete_domain.rb', line 30 def delete_domain(domain_name) response = Excon::Response.new if @data[:domains].delete(domain_name) response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } end response end |
#domain_metadata(domain_name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fog/aws/requests/simpledb/domain_metadata.rb', line 39 def (domain_name) response = Excon::Response.new if domain = @data[:domains][domain_name] response.status = 200 attribute_names = [] attribute_values = [] for item in domain.values for key, values in item attribute_names << key for value in values attribute_values << value end end end response.body = { 'AttributeNameCount' => attribute_names.length, 'AttributeNamesSizeBytes' => attribute_names.join('').length, 'AttributeValueCount' => attribute_values.length, 'AttributeValuesSizeBytes' => attribute_values.join('').length, 'BoxUsage' => Fog::AWS::Mock.box_usage, 'ItemCount' => domain.keys.length, 'ItemNamesSizeBytes' => domain.keys.join('').length, 'RequestId' => Fog::AWS::Mock.request_id, 'Timestamp' => Time.now } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#get_attributes(domain_name, item_name, attributes = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fog/aws/requests/simpledb/get_attributes.rb', line 43 def get_attributes(domain_name, item_name, attributes = nil) response = Excon::Response.new if @data[:domains][domain_name] object = {} if attributes for attribute in attributes 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 @data[:domains][domain_name][item_name] object = @data[:domains][domain_name][item_name] end response.status = 200 response.body = { 'Attributes' => object, 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#list_domains(options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/aws/requests/simpledb/list_domains.rb', line 35 def list_domains( = {}) response = Excon::Response.new keys = @data[:domains].keys max = ['MaxNumberOfDomains'] || keys.size offset = ['NextToken'] || 0 domains = [] for key, value in @data[:domains].keys[offset...max] domains << key end response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'Domains' => domains, 'RequestId' => Fog::AWS::Mock.request_id } if max < keys.size response.body['NextToken'] = max + 1 end response end |
#put_attributes(domain_name, item_name, attributes, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fog/aws/requests/simpledb/put_attributes.rb', line 42 def put_attributes(domain_name, item_name, attributes, = {}) [:expect] = {} unless [:expect] [:replace] = [] unless [:replace] response = Excon::Response.new if @data[:domains][domain_name] [:expect].each do |ck, cv| if @data[:domains][domain_name][item_name][ck] != [cv] response.status = 409 raise(Excon::Errors.status_error({:expects => 200}, response)) end end attributes.each do |key, value| @data[:domains][domain_name][item_name] ||= {} @data[:domains][domain_name][item_name][key.to_s] = [] unless @data[:domains][domain_name][item_name][key.to_s] if [:replace].include?(key.to_s) @data[:domains][domain_name][item_name][key.to_s] = [*value].map {|x| x.to_s} else @data[:domains][domain_name][item_name][key.to_s] += [*value].map {|x| x.to_s} end end response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#select(select_expression, next_token = nil) ⇒ Object
36 37 38 |
# File 'lib/fog/aws/requests/simpledb/select.rb', line 36 def select(select_expression, next_token = nil) Fog::Mock.not_implemented end |