Module: RactorRailsShim::ActiveModelAttributeRegistrationPatch::InstanceMethods
- Defined in:
- lib/ractor_rails_shim/patches/active_model_attribute.rb
Instance Method Summary collapse
-
#_default_attributes ⇒ Object
:nodoc:.
-
#attribute_types ⇒ Object
:nodoc:.
-
#reset_default_attributes! ⇒ Object
reset_default_attributes!(called byreload_schema_from_cachevia the Attributes → Timestamp → ModelSchema super chain) writes@default_attributes = niland@attribute_types = nilclass ivars.
Instance Method Details
#_default_attributes ⇒ Object
:nodoc:
51 52 53 54 55 56 57 |
# File 'lib/ractor_rails_shim/patches/active_model_attribute.rb', line 51 def _default_attributes # :nodoc: key = :"rrs_default_attributes_#{object_id}" ActiveSupport::IsolatedExecutionState[key] ||= ::ActiveModel::AttributeSet.new({}).tap do |attribute_set| apply_pending_attribute_modifications(attribute_set) end end |
#attribute_types ⇒ Object
:nodoc:
59 60 61 62 63 64 65 66 |
# File 'lib/ractor_rails_shim/patches/active_model_attribute.rb', line 59 def attribute_types # :nodoc: key = :"rrs_attribute_types_#{object_id}" ActiveSupport::IsolatedExecutionState[key] ||= begin types = _default_attributes.cast_types types.default = ::ActiveModel::Type.default_value types end end |
#reset_default_attributes! ⇒ Object
reset_default_attributes! (called by reload_schema_from_cache via
the Attributes → Timestamp → ModelSchema super chain) writes
@default_attributes = nil and @attribute_types = nil class ivars.
In a worker Ractor those writes raise Ractor::IsolationError. The
shim routes the readers above through IES, so in a worker we clear
the IES slots instead (the next read rebuilds lazily). In main we keep
the original class-ivar-clearing behavior.
75 76 77 78 79 80 81 82 83 |
# File 'lib/ractor_rails_shim/patches/active_model_attribute.rb', line 75 def reset_default_attributes! if Ractor.main? @default_attributes = nil @attribute_types = nil else ActiveSupport::IsolatedExecutionState.delete(:"rrs_default_attributes_#{object_id}") ActiveSupport::IsolatedExecutionState.delete(:"rrs_attribute_types_#{object_id}") end end |