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:
39 40 41 |
# File 'lib/duck_record/model_schema.rb', line 39 def _default_attributes # :nodoc: @default_attributes ||= AttributeSet.new({}) end |
#attribute_types ⇒ Object
:nodoc:
11 12 13 14 |
# File 'lib/duck_record/model_schema.rb', line 11 def attribute_types # :nodoc: load_schema @attribute_types ||= Hash.new 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
31 32 33 34 35 36 37 |
# File 'lib/duck_record/model_schema.rb', line 31 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:
16 17 18 |
# File 'lib/duck_record/model_schema.rb', line 16 def yaml_encoder # :nodoc: @yaml_encoder ||= AttributeSet::YAMLEncoder.new(attribute_types) end |