Sha256: eec6d42713d270e6c3b255fd7a6577c55e47e1589395a479738417cd66661104
Contents?: true
Size: 368 Bytes
Versions: 1
Compression:
Stored size: 368 Bytes
Contents
module Discriminator module Methods def discriminate(module_name, on:, default: :base) define_singleton_method :discriminate_class_for_record, ->(attrs) { begin "#{module_name.to_s.camelize}::#{attrs.fetch(on.to_s, default).to_s.camelize}".constantize rescue NameError super(attrs) end } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
discriminator-0.1.1 | lib/discriminator/methods.rb |