Class: ActiveRecord::Attribute::UserProvidedDefault
- Inherits:
-
FromUser
- Object
- ActiveRecord::Attribute
- FromUser
- ActiveRecord::Attribute::UserProvidedDefault
- Defined in:
- 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.
6 7 8 9 |
# File 'lib/active_record/attribute/user_provided_default.rb', line 6 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
11 12 13 14 15 16 17 |
# File 'lib/active_record/attribute/user_provided_default.rb', line 11 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
19 20 21 |
# File 'lib/active_record/attribute/user_provided_default.rb', line 19 def with_type(type) self.class.new(name, user_provided_value, type, original_attribute) end |