AWS::Record is an ORM built on top of AWS services.
for backwards compatability with the old AWS::Record::Base
A utility method for casting values into an array.
nil is returned as an empty array, []
Arrays are returned unmodified
Everything else is returned as the sole element of an array
@param [Object] value @return [Array] The value cast into an array @private
# File lib/aws/record.rb, line 85 def self.as_array value case value when nil then [] when Set then value.to_a when Array then value else [value] end end
A utility method for casting values into
Sets are returned unmodified
everything else is passed through #{::as_array} and then into a new Set
@param [Object] value @return [Set] The value cast into a Set. @private
# File lib/aws/record.rb, line 102 def self.as_set value case value when Set then value else Set.new(as_array(value)) end end
@return [String,nil] The string that is prepended to all domain names.
# File lib/aws/record.rb, line 48 def self.domain_prefix @domain_prefix end
Sets a prefix to be applied to all SimpleDB domains associated with AWS::Record::Base classes.
AWS::Record.domain_prefix = 'production_' class Product < AWS::Record::Base set_domain_name 'products' end Product.domain_name #=> 'production_products'
@param [String] A prefix to append to all domains. This is useful for
grouping domains used by one application with a single prefix.
# File lib/aws/record.rb, line 43 def self.domain_prefix= prefix @domain_prefix = prefix end
@return [String,nil] The string that is prepended to all table names.
# File lib/aws/record.rb, line 72 def self.table_prefix @table_prefix end
Sets a prefix to be applied to all DynamoDB tables associated with {AWS::Record::HashModel} and {AWS::Record::ListModel} classes.
AWS::Record.table_prefix = 'production_' class Product < AWS::Record::HashModel set_table_name 'products' end Product.table_name #=> 'production_products'
@param [String] A prefix to append to all tables. This is
useful for grouping tables used by one application with a single prefix.
# File lib/aws/record.rb, line 67 def self.table_prefix= prefix @table_prefix = prefix end
# File spec/aws/record/model/instance_methods_spec.rb, line 162 def foo self['foo'] ? self['foo'] * 2 : nil end
# File spec/shared/aws_record_examples.rb, line 41 def item_with_attributes attributes attributes = Core::IndifferentHash.new(attributes) item_id = attributes.delete('id') || 'item-id' sdb_data_hash = {} attributes.each_pair do |attr_name, attr_value| values = AWS::Record.as_array(attr_value) sdb_data_hash[attr_name.to_s] = values attr_macro = case values.first when String then :string_attr when Integer then :integer_attr else raise 'unsupported attr type' end klass.send(attr_macro, attr_name, :set => attr_value.is_a?(Array)) end sdb_data.stub(:attributes).and_return(sdb_data_hash) obj = klass['item-id'] obj.instance_variable_set('@_id', item_id) obj end
# File spec/aws/record/model/instance_methods_spec.rb, line 209 def name self['name'] ? self['name'].upcase : nil end
# File spec/aws/record/model/instance_methods_spec.rb, line 193 def name= value self['name'] = value.upcase end