Class: ActiveRecord::Attribute::UserProvidedDefault
- Inherits:
-
FromUser
- Object
- ActiveRecord::Attribute
- FromUser
- ActiveRecord::Attribute::UserProvidedDefault
- Defined in:
- activerecord/lib/active_record/attribute/user_provided_default.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from ActiveRecord::Attribute
Instance Method Summary collapse
-
#initialize(name, value, type, database_default) ⇒ UserProvidedDefault
constructor
A new instance of UserProvidedDefault.
- #value_before_type_cast ⇒ Object
- #with_type(type) ⇒ Object
Methods inherited from ActiveRecord::Attribute
#==, #came_from_user?, #changed?, #changed_in_place?, #encode_with, #forgetting_assignment, from_database, from_user, #has_been_read?, #hash, #init_with, #initialized?, null, #original_value, #type_cast, uninitialized, #value, #value_for_database, #with_cast_value, with_cast_value, #with_value_from_database, #with_value_from_user
Constructor Details
#initialize(name, value, type, database_default) ⇒ UserProvidedDefault
Returns a new instance of UserProvidedDefault.
8 9 10 11 |
# File 'activerecord/lib/active_record/attribute/user_provided_default.rb', line 8 def initialize(name, value, type, database_default) @user_provided_value = value super(name, value, type, database_default) end |
Instance Method Details
#value_before_type_cast ⇒ Object
13 14 15 16 17 18 19 |
# File 'activerecord/lib/active_record/attribute/user_provided_default.rb', line 13 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) ⇒ Object
21 22 23 |
# File 'activerecord/lib/active_record/attribute/user_provided_default.rb', line 21 def with_type(type) self.class.new(name, user_provided_value, type, original_attribute) end |