Sha256: 3ecf89a71b295fd1e10710b02489b4ae544fb128cc5034eb081eff8b091279f2

Contents?: true

Size: 775 Bytes

Versions: 22

Compression:

Stored size: 775 Bytes

Contents

module Wukong
  RESOURCE_CLASS_MAP = { }

  #
  # Find the class from its underscored name. Note the klass is non-modularized.
  # You can also pre-seed RESOURCE_CLASS_MAP
  #
  def self.class_from_resource rsrc
    # This method has been profiled, so don't go making it more elegant unless you're doing same.
    klass_name = rsrc.to_s
    return RESOURCE_CLASS_MAP[klass_name] if RESOURCE_CLASS_MAP.include?(klass_name)
    # kill off all but the non-modularized class name and camelize
    klass_name.gsub!(/(?:^|_)(.)/){ $1.upcase }
    begin
      # convert it to class name
      klass = klass_name.constantize
    rescue Exception => e
      warn "Bogus class name '#{klass_name}'? #{e}"
      klass = nil
    end
    RESOURCE_CLASS_MAP[klass_name] = klass
  end

end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
mrflip-wukong-0.1.0 lib/wukong/datatypes.rb
wukong-3.0.0.pre old/wukong/datatypes.rb
wukong-2.0.2 lib/wukong/datatypes.rb
wukong-2.0.1 lib/wukong/datatypes.rb
wukong-2.0.0 lib/wukong/datatypes.rb
wukong-1.5.4 lib/wukong/datatypes.rb
wukong-1.5.3 lib/wukong/datatypes.rb
wukong-1.5.2 lib/wukong/datatypes.rb
wukong-1.5.1 lib/wukong/datatypes.rb
wukong-1.5.0 lib/wukong/datatypes.rb
wukong-1.4.12 lib/wukong/datatypes.rb
wukong-1.4.11 lib/wukong/datatypes.rb
wukong-1.4.10 lib/wukong/datatypes.rb
wukong-1.4.9 lib/wukong/datatypes.rb
wukong-1.4.7 lib/wukong/datatypes.rb
wukong-1.4.6 lib/wukong/datatypes.rb
wukong-1.4.5 lib/wukong/datatypes.rb
wukong-1.4.2 lib/wukong/datatypes.rb
wukong-1.4.1 lib/wukong/datatypes.rb
wukong-1.4.0 lib/wukong/datatypes.rb