Module: DuckRecord::ModelSchema::ClassMethods
- Defined in:
- lib/duck_record/model_schema.rb
Instance Method Summary collapse
-
#_default_attributes ⇒ Object
:nodoc:.
-
#attribute_types ⇒ Object
:nodoc:.
-
#type_for_attribute(attr_name, &block) ⇒ Object
Returns the type of the attribute with the given name, after applying all modifiers.
-
#yaml_encoder ⇒ Object
:nodoc:.
Instance Method Details
#_default_attributes ⇒ Object
:nodoc:
38 39 40 |
# File 'lib/duck_record/model_schema.rb', line 38 def _default_attributes # :nodoc: @default_attributes ||= AttributeSet.new({}) end |
#attribute_types ⇒ Object
:nodoc:
10 11 12 13 |
# File 'lib/duck_record/model_schema.rb', line 10 def attribute_types # :nodoc: load_schema @attribute_types ||= Hash.new(Type.default_value) end |
#type_for_attribute(attr_name, &block) ⇒ Object
Returns the type of the attribute with the given name, after applying all modifiers. This method is the only valid source of information for anything related to the types of a model’s attributes. This method will access the database and load the model’s schema if it is required.
The return value of this method will implement the interface described by ActiveModel::Type::Value (though the object itself may not subclass it).
attr_name
The name of the attribute to retrieve the type for. Must be a string
30 31 32 33 34 35 36 |
# File 'lib/duck_record/model_schema.rb', line 30 def type_for_attribute(attr_name, &block) if block attribute_types.fetch(attr_name, &block) else attribute_types[attr_name] end end |
#yaml_encoder ⇒ Object
:nodoc:
15 16 17 |
# File 'lib/duck_record/model_schema.rb', line 15 def yaml_encoder # :nodoc: @yaml_encoder ||= AttributeSet::YAMLEncoder.new(attribute_types) end |