Class: AWS::Record::Attributes::BaseAttr

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/record/attributes.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ BaseAttr

Returns a new instance of BaseAttr.

Options Hash (options):

  • :persist_as (String)

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

  • :set (Boolean) — default: false

    When true this attribute can accept multiple unique values.



31
32
33
34
35
36
37
# 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

Instance Attribute Details

#nameString (readonly)



40
41
42
# File 'lib/aws/record/attributes.rb', line 40

def name
  @name
end

#optionsHash (readonly)



43
44
45
# File 'lib/aws/record/attributes.rb', line 43

def options
  @options
end

Class Method Details

.allow_set?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).

Raises:

  • (NotImplementedError)


90
91
92
# File 'lib/aws/record/attributes.rb', line 90

def self.allow_set?
  raise NotImplementedError
end

.deserialize(serialized_value, options = {}) ⇒ Mixed



83
84
85
# File 'lib/aws/record/attributes.rb', line 83

def self.deserialize serialized_value, options = {}
  self.type_cast(serialized_value, options)
end

Instance Method Details

#default_valueObject



52
53
54
# File 'lib/aws/record/attributes.rb', line 52

def default_value
  options[:default_value]
end

#deserialize(serialized_value) ⇒ Mixed



70
71
72
# File 'lib/aws/record/attributes.rb', line 70

def deserialize serialized_value
  self.class.deserialize(serialized_value, options)
end

#persist_asString



58
59
60
# File 'lib/aws/record/attributes.rb', line 58

def persist_as
  (options[:persist_as] || @name).to_s
end

#serialize(type_casted_value) ⇒ Mixed

Takes the type casted value and serializes it



77
78
79
# File 'lib/aws/record/attributes.rb', line 77

def serialize type_casted_value
  self.class.serialize(type_casted_value, options)
end

#set?Boolean



47
48
49
# File 'lib/aws/record/attributes.rb', line 47

def set?
  options[:set] ? true : false
end

#type_cast(raw_value) ⇒ Mixed



64
65
66
# File 'lib/aws/record/attributes.rb', line 64

def type_cast raw_value
  self.class.type_cast(raw_value, options)
end