Module: DuckRecord::ModelSchema::ClassMethods
- Defined in:
- lib/duck_record/model_schema.rb
Instance Method Summary collapse
-
#_default_attributes ⇒ Object
:nodoc:.
-
#attribute_types ⇒ Object
:nodoc:.
-
#attributes_builder ⇒ 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:
43 44 45 |
# File 'lib/duck_record/model_schema.rb', line 43 def _default_attributes # :nodoc: @default_attributes ||= AttributeSet.new({}) end |
#attribute_types ⇒ Object
:nodoc:
15 16 17 18 |
# File 'lib/duck_record/model_schema.rb', line 15 def attribute_types # :nodoc: load_schema @attribute_types ||= Hash.new end |
#attributes_builder ⇒ Object
:nodoc:
11 12 13 |
# File 'lib/duck_record/model_schema.rb', line 11 def attributes_builder # :nodoc: @attributes_builder ||= AttributeSet::Builder.new(attribute_types) 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
35 36 37 38 39 40 41 |
# File 'lib/duck_record/model_schema.rb', line 35 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:
20 21 22 |
# File 'lib/duck_record/model_schema.rb', line 20 def yaml_encoder # :nodoc: @yaml_encoder ||= AttributeSet::YAMLEncoder.new(attribute_types) end |