Sha256: a619a9fa7e6495e9b7e37330b8db2b07bb871cce15eac4022c0fa7f06db8c434

Contents?: true

Size: 361 Bytes

Versions: 1

Compression:

Stored size: 361 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
        end
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
discriminator-0.1.0 lib/discriminator/methods.rb