123456789_123456789_123456789_123456789_123456789_

Class: ActiveModel::Attribute::UserProvidedDefault

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveModel::Attribute::FromUser
Defined in: activemodel/lib/active_model/attribute/user_provided_default.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name, value, type, database_default) ⇒ UserProvidedDefault

[ GitHub ]

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

def initialize(name, value, type, database_default)
  @user_provided_value = value
  super(name, value, type, database_default)
end

Instance Attribute Details

#user_provided_value (readonly, private)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute/user_provided_default.rb', line 52

attr_reader :user_provided_value

Instance Method Details

#marshal_dump

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute/user_provided_default.rb', line 29

def marshal_dump
  result = [
    name,
    value_before_type_cast,
    type,
    original_attribute,
  ]
  result << value if defined?(@value)
  result
end

#marshal_load(values)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute/user_provided_default.rb', line 40

def marshal_load(values)
  name, user_provided_value, type, original_attribute, value = values
  @name = name
  @user_provided_value = user_provided_value
  @type = type
  @original_attribute = original_attribute
  if values.length == 5
    @value = value
  end
end

#value_before_type_cast

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute/user_provided_default.rb', line 17

def value_before_type_cast
  if user_provided_value.is_a?(Proc)
    @memoized_value_before_type_cast ||= user_provided_value.call
  else
    @user_provided_value
  end
end

#with_type(type)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute/user_provided_default.rb', line 25

def with_type(type)
  self.class.new(name, user_provided_value, type, original_attribute)
end