Sha256: b2d5273aa651c1f2a2d17538d705fd96b9565893ac78c3b589ca178c5d132114

Contents?: true

Size: 711 Bytes

Versions: 28

Compression:

Stored size: 711 Bytes

Contents

module Avo
  module Concerns
    module ModelClassConstantized
      extend ActiveSupport::Concern

      class_methods do
        # Cast the model class to a constantized version and memoize it like that
        def model_class=(value)
          @model_class = value
        end

        # Cast the model class to a constantized version
        def constantized_model_class
          @constantized_model_class ||= case @model_class
          when Class
            @model_class
          when String, Symbol
            @model_class.to_s.safe_constantize
          else
            raise ArgumentError.new "Failed to find a proper model class for #{self}"
          end
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
avo-3.16.4 lib/avo/concerns/model_class_constantized.rb
avo-3.16.3 lib/avo/concerns/model_class_constantized.rb
avo-3.16.2 lib/avo/concerns/model_class_constantized.rb
avo-3.16.1 lib/avo/concerns/model_class_constantized.rb
avo-3.16.0 lib/avo/concerns/model_class_constantized.rb
avo-3.15.7 lib/avo/concerns/model_class_constantized.rb
avo-3.15.6 lib/avo/concerns/model_class_constantized.rb
avo-3.15.5 lib/avo/concerns/model_class_constantized.rb
avo-3.15.4 lib/avo/concerns/model_class_constantized.rb
avo-3.15.3 lib/avo/concerns/model_class_constantized.rb
avo-3.15.2 lib/avo/concerns/model_class_constantized.rb
avo-3.15.1 lib/avo/concerns/model_class_constantized.rb
avo-3.15.0 lib/avo/concerns/model_class_constantized.rb
avo-3.14.5 lib/avo/concerns/model_class_constantized.rb
avo-3.14.4 lib/avo/concerns/model_class_constantized.rb
avo-3.14.3 lib/avo/concerns/model_class_constantized.rb
avo-3.14.2 lib/avo/concerns/model_class_constantized.rb
avo-3.14.1 lib/avo/concerns/model_class_constantized.rb
avo-3.14.0 lib/avo/concerns/model_class_constantized.rb
avo-3.13.7 lib/avo/concerns/model_class_constantized.rb