Module: Aws::Record::Attributes
- Included in:
- Aws::Record
- Defined in:
- lib/aws-record/record/attributes.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attr_values = {}) ⇒ Aws::Record
Base initialization method for a new item.
-
#to_h ⇒ Hash
Returns a hash representation of the attribute data.
Class Method Details
.included(sub_class) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/aws-record/record/attributes.rb', line 6 def self.included(sub_class) sub_class.extend(ClassMethods) model_attributes = ModelAttributes.new(self) sub_class.instance_variable_set('@attributes', model_attributes) sub_class.instance_variable_set('@keys', KeyAttributes.new(model_attributes)) inherit_attributes(sub_class) if Aws::Record.extends_record?(sub_class) end |
Instance Method Details
#initialize(attr_values = {}) ⇒ Aws::Record
Base initialization method for a new item. Optionally, allows you to provide initial attribute values for the model. You do not need to provide all, or even any, attributes at item creation time.
Inheritance Support
Child models will inherit the attributes and keys defined in the parent model. Child models can override attribute keys if defined in their own model.
See examples below to see the feature in action.
63 64 65 66 67 68 69 70 71 |
# File 'lib/aws-record/record/attributes.rb', line 63 def initialize(attr_values = {}) opts = { track_mutations: self.class.mutation_tracking_enabled? } @data = ItemData.new(self.class.attributes, opts) attr_values.each do |attr_name, attr_value| send("#{attr_name}=", attr_value) end end |
#to_h ⇒ Hash
Returns a hash representation of the attribute data.
76 77 78 |
# File 'lib/aws-record/record/attributes.rb', line 76 def to_h @data.hash_copy end |