Module: Grape::Util::FreezeOnNew
- Included in:
- Validations::Types::CustomTypeCoercer, Validations::Types::DryTypeCoercer, Validations::Types::MultipleTypeCoercer, Validations::Types::VariantCollectionCoercer, Validations::Validators::Base, Validations::Validators::ContractScopeValidator
- Defined in:
- lib/grape/util/freeze_on_new.rb
Overview
Extend into a class whose instances are shared across requests:
new returns a frozen instance, so any later ivar write — e.g.
request-time memoization — raises FrozenError instead of being a
latent data race.
Must stay a new wrapper (never an initialize wrapper): the freeze
runs after the entire initialize chain, so subclasses may assign ivars
after super. Extending a hierarchy base covers its subclasses —
singleton classes inherit along the class hierarchy.
Instance Method Summary collapse
Instance Method Details
#new ⇒ Object
15 16 17 |
# File 'lib/grape/util/freeze_on_new.rb', line 15 def new(...) super.freeze end |