Class: AWS::Record::Attributes::StringAttr
- Defined in:
- lib/aws/record/attributes.rb
Instance Attribute Summary
Attributes inherited from BaseAttr
Class Method Summary collapse
- .allow_set? ⇒ Boolean
-
.serialize(string, options = {}) ⇒ String
Returns a serialized representation of the string value suitable for storing in SimpleDB.
-
.type_cast(raw_value, options = {}) ⇒ String?
Returns the value cast to a string.
Methods inherited from BaseAttr
#default_value, deserialize, #deserialize, #initialize, #persist_as, #serialize, #set?, #type_cast
Constructor Details
This class inherits a constructor from AWS::Record::Attributes::BaseAttr
Class Method Details
.allow_set? ⇒ Boolean
147 148 149 |
# File 'lib/aws/record/attributes.rb', line 147 def self.allow_set? true end |
.serialize(string, options = {}) ⇒ String
Returns a serialized representation of the string value suitable for storing in SimpleDB.
138 139 140 141 142 143 144 |
# File 'lib/aws/record/attributes.rb', line 138 def self.serialize string, = {} unless string.is_a?(String) msg = "expected a String value, got #{string.class}" raise ArgumentError, msg end string end |
.type_cast(raw_value, options = {}) ⇒ String?
Returns the value cast to a string. Empty strings are returned as nil by default. Type casting is done by calling #to_s on the value.
string_attr.type_cast(123)
# => '123'
string_attr.type_cast('')
# => nil
string_attr.type_cast('', :preserve_empty_strings => true)
# => ''
124 125 126 127 128 129 130 131 |
# File 'lib/aws/record/attributes.rb', line 124 def self.type_cast raw_value, = {} case raw_value when nil then nil when '' then [:preserve_empty_strings] ? '' : nil when String then raw_value else raw_value.to_s end end |