Module: ActiveEntity::ModelSchema::ClassMethods

Defined in:
lib/active_entity/model_schema.rb

Instance Method Summary collapse

Instance Method Details

#_default_attributesObject

:nodoc:



53
54
55
56
# File 'lib/active_entity/model_schema.rb', line 53

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

#attribute_typesObject

:nodoc:



24
25
26
27
# File 'lib/active_entity/model_schema.rb', line 24

def attribute_types # :nodoc:
  load_schema
  @attribute_types ||= Hash.new(Type.default_value)
end

#attributes_builderObject

:nodoc:



16
17
18
19
20
21
22
# File 'lib/active_entity/model_schema.rb', line 16

def attributes_builder # :nodoc:
  unless defined?(@attributes_builder) && @attributes_builder
    defaults = _default_attributes
    @attributes_builder = ActiveModel::AttributeSet::Builder.new(attribute_types, defaults)
  end
  @attributes_builder
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 or a symbol.



44
45
46
47
48
49
50
51
# File 'lib/active_entity/model_schema.rb', line 44

def type_for_attribute(attr_name, &block)
  attr_name = attr_name.to_s
  if block
    attribute_types.fetch(attr_name, &block)
  else
    attribute_types[attr_name]
  end
end

#yaml_encoderObject

:nodoc:



29
30
31
# File 'lib/active_entity/model_schema.rb', line 29

def yaml_encoder # :nodoc:
  @yaml_encoder ||= ActiveModel::AttributeSet::YAMLEncoder.new(attribute_types)
end