module DuckRecord::ModelSchema::ClassMethods
Public Instance Methods
type_for_attribute(attr_name, &block)
click to toggle source
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
# 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
Private Instance Methods
load_schema()
click to toggle source
# File lib/duck_record/model_schema.rb, line 48 def load_schema unless schema_loaded? load_schema! end end
load_schema!()
click to toggle source
# File lib/duck_record/model_schema.rb, line 54 def load_schema! @schema_loaded = true end
reload_schema_from_cache()
click to toggle source
# File lib/duck_record/model_schema.rb, line 58 def reload_schema_from_cache @attribute_types = nil @default_attributes = nil @attributes_builder = nil @schema_loaded = false @attribute_names = nil @yaml_encoder = nil direct_descendants.each do |descendant| descendant.send(:reload_schema_from_cache) end end
schema_loaded?()
click to toggle source
# File lib/duck_record/model_schema.rb, line 44 def schema_loaded? defined?(@schema_loaded) && @schema_loaded end