class AWS::Record::Attributes::BaseAttr

Base class for all of the AWS::Record attributes.

Attributes

name[R]

@return [String] The name of this attribute

options[R]

@return [Hash] Attribute options passed to the constructor.

Public Class Methods

allow_set?() click to toggle source

@return [Boolean] Returns true if this attribute type can be used

with the +:set => true+ option.  Certain attirbutes can not 
be represented with multiple values (like BooleanAttr).
# File lib/aws/record/attributes.rb, line 90
def self.allow_set?
  raise NotImplementedError
end
deserialize(serialized_value, options = {}) click to toggle source

@param [String] serialized_value The raw value returned from AWS. @return [Mixed] Returns the type-casted deserialized value.

# File lib/aws/record/attributes.rb, line 83
def self.deserialize serialized_value, options = {}
  self.type_cast(serialized_value, options)
end
new(name, options = {}) click to toggle source

@param [Symbol] Name of this attribute. It should be a name that

is safe to use as a method.

@param [Hash] options @option options [String] :#persist_as Defaults to the name of the

attribute.  You can pass a string to specify what the attribute
will be named in the backend storage.

@option options [Boolean] :set (false) When true this attribute can

accept multiple unique values.
# File lib/aws/record/attributes.rb, line 31
def initialize name, options = {}
  @name = name.to_s
  @options = options.dup
  if options[:set] and !self.class.allow_set?
    raise ArgumentError, "invalid option :set for #{self.class}"
  end
end

Protected Class Methods

expect(klass, value) { || ... } click to toggle source

@private

# File lib/aws/record/attributes.rb, line 96
def self.expect klass, value, &block
  unless value.is_a?(klass)
    raise ArgumentError, "expected a #{klass}, got #{value.class}"
  end
  yield if block_given?
end

Public Instance Methods

default_value() click to toggle source

@return Returns the default value for this attribute.

# File lib/aws/record/attributes.rb, line 52
def default_value
  options[:default_value]
end
deserialize(serialized_value) click to toggle source

@param [String] The serialized string value. @return [Mixed] Returns a deserialized type-casted value.

# File lib/aws/record/attributes.rb, line 70
def deserialize serialized_value
  self.class.deserialize(serialized_value, options)
end
persist_as() click to toggle source

@return [String] Returns the name this attribute will use

in the storage backend.
# File lib/aws/record/attributes.rb, line 58
def persist_as
  (options[:persist_as] || @name).to_s
end
serialize(type_casted_value) click to toggle source

Takes the type casted value and serializes it @param [Mixed] A single value to serialize. @return [Mixed] Returns the serialized value.

# File lib/aws/record/attributes.rb, line 77
def serialize type_casted_value
  self.class.serialize(type_casted_value, options)
end
set?() click to toggle source

@return [Boolean] Returns true if this attribute can have

multiple values.
# File lib/aws/record/attributes.rb, line 47
def set?
  options[:set] ? true : false
end
type_cast(raw_value) click to toggle source

@param [Mixed] A single value to type cast. @return [Mixed] Returns the type casted value.

# File lib/aws/record/attributes.rb, line 64
def type_cast raw_value
  self.class.type_cast(raw_value, options)
end