123456789_123456789_123456789_123456789_123456789_

Module: ActiveModel::AttributeRegistration::ClassMethods

Do not use. This module is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Defined in: activemodel/lib/active_model/attribute_registration.rb

Instance Method Summary

Instance Method Details

#_default_attributes

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_registration.rb', line 22

def _default_attributes # :nodoc:
  @default_attributes ||= build_default_attributes
end

#apply_pending_attributes(attribute_set)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_registration.rb', line 48

def apply_pending_attributes(attribute_set)
  superclass.send(__method__, attribute_set) if superclass.respond_to?(__method__, true)

  defined?(@pending_attributes) && @pending_attributes.each do |name, pending|
    attribute_set[name] = pending.apply_to(attribute_set[name])
  end

  attribute_set
end

#attribute(name, type = nil, default: (no_default = true), **options)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_registration.rb', line 12

def attribute(name, type = nil, default: (no_default = true), **options)
  type = resolve_type_name(type, **options) if type.is_a?(Symbol)

  pending = pending_attribute(name)
  pending.type = type if type
  pending.default = default unless no_default

  reset_default_attributes
end

#attribute_types

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_registration.rb', line 26

def attribute_types # :nodoc:
  @attribute_types ||= _default_attributes.cast_types.tap do |hash|
    hash.default = Type.default_value
  end
end

#build_default_attributes

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_registration.rb', line 58

def build_default_attributes
  apply_pending_attributes(AttributeSet.new({}))
end

#pending_attribute(name)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_registration.rb', line 43

def pending_attribute(name)
  @pending_attributes ||= {}
  @pending_attributes[resolve_attribute_name(name)] ||= PendingAttribute.new
end

#reset_default_attributes

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_registration.rb', line 62

def reset_default_attributes
  @default_attributes = nil
  @attribute_types = nil
  subclasses.each { |subclass| subclass.send(__method__) }
end

#resolve_attribute_name(name)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_registration.rb', line 68

def resolve_attribute_name(name)
  name.to_s
end

#resolve_type_name(name, **options)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_registration.rb', line 72

def resolve_type_name(name, **options)
  Type.lookup(name, **options)
end