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-0.8.5 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.4 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.3 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.2 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.1 motion-prime/helpers/has_class_factory.rb
motion-prime-0.8.0 motion-prime/helpers/has_class_factory.rb
motion-prime-0.7.2 motion-prime/helpers/has_class_factory.rb
motion-prime-0.7.1 motion-prime/helpers/has_class_factory.rb
motion-prime-0.7.0 motion-prime/helpers/has_class_factory.rb
motion-prime-0.6.0 motion-prime/helpers/has_class_factory.rb
motion-prime-0.5.7 motion-prime/helpers/has_class_factory.rb
motion-prime-0.5.6 motion-prime/helpers/has_class_factory.rb
motion-prime-0.5.5 motion-prime/helpers/has_class_factory.rb
motion-prime-0.5.4 motion-prime/helpers/has_class_factory.rb
motion-prime-0.5.3 motion-prime/helpers/has_class_factory.rb
motion-prime-0.5.2 motion-prime/helpers/has_class_factory.rb
motion-prime-0.5.1 motion-prime/helpers/has_class_factory.rb
motion-prime-0.5.0 motion-prime/helpers/has_class_factory.rb
motion-prime-0.4.5 motion-prime/helpers/has_class_factory.rb
motion-prime-0.4.4 motion-prime/helpers/has_class_factory.rb