Sha256: 82fce4491ebcc4b21cbc66d8ba745975827e2e31a4f34d45bbc43f17b80f307c

Contents?: true

Size: 571 Bytes

Versions: 149

Compression:

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

Version data entries

149 entries across 149 versions & 1 rubygems

Version Path
avo-2.53.0 lib/avo/concerns/model_class_constantized.rb
avo-2.52.0 lib/avo/concerns/model_class_constantized.rb
avo-2.49.0 lib/avo/concerns/model_class_constantized.rb
avo-2.48.0 lib/avo/concerns/model_class_constantized.rb
avo-2.47.0 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre13 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre12 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre10 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre11 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre8 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre9 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre7 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre5 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre6 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre4 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre3 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre2 lib/avo/concerns/model_class_constantized.rb
avo-3.0.0.pre1 lib/avo/concerns/model_class_constantized.rb
avo-2.46.0 lib/avo/concerns/model_class_constantized.rb
avo-2.45.0 lib/avo/concerns/model_class_constantized.rb