Class: ActiveModel::Attribute::UserProvidedDefault
- Inherits:
-
FromUser
show all
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/attribute/user_provided_default.rb
Overview
Instance Attribute Summary
#name, #type
Instance Method Summary
collapse
#==, #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, #original_value_for_database, #serializable?, #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 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/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
#marshal_dump ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/attribute/user_provided_default.rb', line 25
def marshal_dump
result = [
name,
value_before_type_cast,
type,
original_attribute,
]
result << value if defined?(@value)
result
end
|
#marshal_load(values) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/attribute/user_provided_default.rb', line 36
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 ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/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 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/attribute/user_provided_default.rb', line 21
def with_type(type)
self.class.new(name, user_provided_value, type, original_attribute)
end
|