Class: ActiveModel::Type::ImmutableString

Inherits:
Value show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/immutable_string.rb

Overview

:nodoc:

Direct Known Subclasses

String

Instance Attribute Summary

Attributes inherited from Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods inherited from Value

#==, #assert_valid_value, #binary?, #cast, #changed?, #changed_in_place?, #deserialize, #force_equality?, #hash, #map, #serializable?, #type_cast_for_schema, #value_constructed_by_mass_assignment?

Constructor Details

#initialize(**args) ⇒ ImmutableString

Returns a new instance of ImmutableString.



6
7
8
9
10
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/immutable_string.rb', line 6

def initialize(**args)
  @true  = -(args.delete(:true)&.to_s  || "t")
  @false = -(args.delete(:false)&.to_s || "f")
  super
end

Instance Method Details

#serialize(value) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/immutable_string.rb', line 16

def serialize(value)
  case value
  when ::Numeric, ::Symbol, ActiveSupport::Duration then value.to_s
  when true then @true
  when false then @false
  else super
  end
end

#typeObject



12
13
14
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/immutable_string.rb', line 12

def type
  :string
end