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:
self,
FromUser ,
::ActiveModel::Attribute
|
|
Instance Chain:
self,
FromUser ,
::ActiveModel::Attribute
|
|
Inherits: |
ActiveModel::Attribute::FromUser
|
Defined in: | activemodel/lib/active_model/attribute/user_provided_default.rb |
Class Method Summary
::ActiveModel::Attribute
- Inherited
.from_database, .from_user, | |
.new | This method should not be called directly. |
.null, .uninitialized, .with_cast_value |
Instance Attribute Summary
Instance Method Summary
FromUser
- Inherited
::ActiveModel::Attribute
- Inherited
Constructor Details
.new(name, value, type, database_default) ⇒ UserProvidedDefault
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