Sha256: ef2b82001542481f5287f106e3f4c9f1c48efbde80b8333059af305d5e5be5ea

Contents?: true

Size: 576 Bytes

Versions: 13

Compression:

Stored size: 576 Bytes

Contents

module Avo
  module Concerns
    module ModelClassConstantized
      extend ActiveSupport::Concern

      class_methods do
        attr_reader :model_class

        # Cast the model class to a constantized version and memoize it like that
        def model_class=(value)
          @model_class = case value
          when Class
            value
          when String, Symbol
            value.to_s.safe_constantize
          else
            raise ArgumentError.new "Failed to find a proper model class for #{self.to_s}"
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
avo-2.11.1.pre.3 lib/avo/concerns/model_class_constantized.rb
avo-2.11.1 lib/avo/concerns/model_class_constantized.rb
avo-2.11.1.pre.2 lib/avo/concerns/model_class_constantized.rb
avo-2.11.1.pre.1 lib/avo/concerns/model_class_constantized.rb
avo-2.11.0 lib/avo/concerns/model_class_constantized.rb
avo-2.10.3.pre.1 lib/avo/concerns/model_class_constantized.rb
avo-2.10.2 lib/avo/concerns/model_class_constantized.rb
avo-2.10.0 lib/avo/concerns/model_class_constantized.rb
avo-2.9.1.pre7 lib/avo/concerns/model_class_constantized.rb
avo-2.9.1.pre6 lib/avo/concerns/model_class_constantized.rb
avo-2.9.1.pre5 lib/avo/concerns/model_class_constantized.rb
avo-2.9.1.pre4 lib/avo/concerns/model_class_constantized.rb
avo-2.9.1.pre2 lib/avo/concerns/model_class_constantized.rb