Sha256: efe56065d2ff684001652c3b1fc9b7ed3297b71c3a07425122c0021a158cb1f6

Contents?: true

Size: 1.06 KB

Versions: 41

Compression:

Stored size: 1.06 KB

Contents

# These things required because camelize/constantize/classify methods are very slow
module MotionPrime
  module HasClassFactory
    def class_factory(name, is_mp_class = false)
      if is_mp_class
        value = Prime.class_factory_cache["motion_prime/#{name}"]
        return value if value
        class_name = camelize_factory(name)

        return nil unless MotionPrime.const_defined?(class_name)
        class_name = "MotionPrime::#{class_name}"
        name = "motion_prime/#{name}"
      else
        value = Prime.class_factory_cache[name]
        return value if value
        class_name = camelize_factory(name)
      end
      Prime.class_factory_cache[name] = class_name.constantize
    end

    def camelize_factory(name)
      value = Prime.camelize_factory_cache[name]
      return value if value
      Prime.camelize_factory_cache[name] = name.camelize
    end

    def low_camelize_factory(name)
      value = Prime.low_camelize_factory_cache[name]
      return value if value
      Prime.low_camelize_factory_cache[name] = name.camelize(:lower)
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
motion-prime-1.0.0 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.9.2 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.9.1 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.9 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.8 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.7 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.6 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.5 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.4 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.3 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.2 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.1 motion-prime/helpers/has_class_factory.rb
motion-prime-0.9.0 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.12 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.11 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.10 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.9 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.8 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.7 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.6 motion-prime/helpers/has_class_factory.rb