Module: Og::MetaUtils

Defined in:
lib/og/meta.rb

Overview

Some useful meta-language utilities.

Class Method Summary collapse

Class Method Details

.expand(klass) ⇒ Object

Convert the klass to a string representation The leading module if available is removed. – gmosx, FIXME: unify with the ogutils.encode method? ++



25
26
27
# File 'lib/og/meta.rb', line 25

def self.expand(klass)
	return klass.name.gsub(/^.*::/, '').gsub(/::/, '_').downcase
end

.resolve_class(name, klass) ⇒ Object

Infer the target klass for a relation. When defining relations, tha target class is typically given. Some times in order to avoid forward declarations a symbol is given instead of a class. Other times on class is given at all, and the inflection mechanism is used to infer the class name.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/og/meta.rb', line 35

def self.resolve_class(name, klass)
	klass ||= N::Inflector.camelize(name)
	
	return klass if klass.is_a?(Class)
	
	unless klass.is_a?(String) or klass.is_a?(Symbol)
		raise 'Invalid class definition' 
	end

	unless Object.const_get(klass.intern)
		# Forward declaration.
		Object.class_eval("class #{klass}; end")
	end

	return Object.const_get(klass)
end