Module: T::Enum::LegacyMigrationMode

Extended by:
Helpers
Includes:
Kernel
Defined in:
lib/types/enum.rb

Constant Summary

Constants included from Helpers

Helpers::Private

Instance Method Summary collapse

Methods included from Helpers

abstract!, final!, interface!, mixes_in_class_methods, requires_ancestor, sealed!

Methods included from Sig

#sig

Instance Method Details

#==(other) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/types/enum.rb', line 226

def ==(other)
  case other
  when String
    if T::Configuration.legacy_t_enum_migration_mode?
      comparison_assertion_failed(:==, other)
      self.serialize == other
    else
      false
    end
  else
    super(other)
  end
end

#===(other) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/types/enum.rb', line 242

def ===(other)
  case other
  when String
    if T::Configuration.legacy_t_enum_migration_mode?
      comparison_assertion_failed(:===, other)
      self.serialize == other
    else
      false
    end
  else
    super(other)
  end
end

#serializeObject



197
# File 'lib/types/enum.rb', line 197

def serialize; end

#to_strObject



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/types/enum.rb', line 208

def to_str
  msg = 'Implicit conversion of Enum instances to strings is not allowed. Call #serialize instead.'
  if T::Configuration.legacy_t_enum_migration_mode?
    T::Configuration.soft_assert_handler(
      msg,
      storytime: {
        class: self.class.name,
        caller_location: Kernel.caller_locations(1..1)&.[](0)&.then {"#{_1.path}:#{_1.lineno}"},
      },
    )
    serialize.to_s
  else
    Kernel.raise NoMethodError.new(msg)
  end
end