Module | AWS::Record::AbstractBase::InstanceMethods |
In: |
lib/aws/record/abstract_base.rb
|
Constructs a new record.
@param [Hash] attributes Attributes that should be bulk assigned
to this record. You can also specify the shard (i.e. domain or table) this record should persist to via `:shard`).
@option attributes [String] :shard The domain/table this record
should persist to. If this is omitted, it will persist to the class default shard (which defaults to the class name).
@return [Model,HashModel] Returns a new (non-persisted) record.
Call {#save} to persist changes to AWS.
@return [Hash] A hash with attribute names as hash keys (strings) and
attribute values (of mixed types) as hash values.
Acts like {update} but does not call {save}.
record.attributes = { :name => 'abc', :age => 20 }
@param [Hash] attributes A hash of attributes to set on this record
without calling save.
@return [Hash] Returns the attribute hash that was passed in.
Persistence indicates if the record has been saved previously or not.
@example
@recipe = Recipe.new(:name => 'Buttermilk Pancackes') @recipe.persisted? #=> false @recipe.save! @recipe.persisted? #=> true
@return [Boolean] Returns true if this record has been persisted.
Creates new records, updates exsting records. If there is a validation error then an exception is raised. @raise [InvalidRecordError] Raised when the record has validation
errors and can not be saved.
@return [true] Returns true after a successful save.
@return [String] Returns the name of the shard this record
is persisted to or will be persisted to. Defaults to the domain/table named after this record class.
Bulk assigns the attributes and then saves the record. @param [Hash] attribute_hash A hash of attribute names (keys) and
attribute values to assign to this record.
@return (see save)
Bulk assigns the attributes and then saves the record. Raises an exception (AWS::Record::InvalidRecordError) if the record is not valid. @param (see update_attributes) @return [true]
@param [Hash] opts Pass :validate => false to skip validations @return [Boolean] Returns true if this record has no validation errors.
Returns the typecasted value for the named attribute.
book = Book.new(:title => 'My Book') book['title'] #=> 'My Book' book.title #=> 'My Book'
### Intended Use
This method‘s primary use is for getting/setting the value for an attribute inside a custom method:
class Book < AWS::Record::Model string_attr :title def title self['title'] ? self['title'].upcase : nil end end book = Book.new(:title => 'My Book') book.title #=> 'MY BOOK'
@param [String,Symbol] attribute_name The name of the attribute to fetch
a value for.
@return The current type-casted value for the named attribute.
If you define a custom setter, you use #[]= to set the value on the record.
class Book < AWS::Record::Model string_attr :name # replace the default #author= method def author= name self['author'] = name.blank? ? 'Anonymous' : name end end
@param [String,Symbol] The attribute name to set a value for @param attribute_value The value to assign.