Module: DuckRecord::ModelSchema::ClassMethods

Defined in:
lib/duck_record/model_schema.rb

Instance Method Summary collapse

Instance Method Details

#_default_attributesObject

:nodoc:



43
44
45
# File 'lib/duck_record/model_schema.rb', line 43

def _default_attributes # :nodoc:
  @default_attributes ||= AttributeSet.new({})
end

#attribute_typesObject

: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_builderObject

: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_encoderObject

: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