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.25.1.pre.1.pr1579 lib/avo/concerns/model_class_constantized.rb
avo-2.26.0 lib/avo/concerns/model_class_constantized.rb
avo-2.25.0 lib/avo/concerns/model_class_constantized.rb
avo-2.24.1 lib/avo/concerns/model_class_constantized.rb
avo-2.24.0 lib/avo/concerns/model_class_constantized.rb
avo-2.23.3.pre.1.pr1529 lib/avo/concerns/model_class_constantized.rb
avo-2.23.2 lib/avo/concerns/model_class_constantized.rb
avo-2.23.1 lib/avo/concerns/model_class_constantized.rb
avo-2.23.0 lib/avo/concerns/model_class_constantized.rb
avo-2.22.0 lib/avo/concerns/model_class_constantized.rb
avo-2.21.3.pre.pr1489 lib/avo/concerns/model_class_constantized.rb
avo-2.21.2.pre.pr1486 lib/avo/concerns/model_class_constantized.rb
avo-2.21.1.pre.pr1484 lib/avo/concerns/model_class_constantized.rb
avo-2.21.0 lib/avo/concerns/model_class_constantized.rb
avo-2.21.1.pre.pr1476 lib/avo/concerns/model_class_constantized.rb
avo-2.21.1.pre.issue1450 lib/avo/concerns/model_class_constantized.rb
avo-2.21.1.pre.issue1444 lib/avo/concerns/model_class_constantized.rb
avo-2.20.0 lib/avo/concerns/model_class_constantized.rb
avo-2.19.0 lib/avo/concerns/model_class_constantized.rb
avo-2.18.1 lib/avo/concerns/model_class_constantized.rb