Class: RGen::MetamodelBuilder::BuildHelper

Inherits:
Object
  • Object
show all
Includes:
NameHelper
Defined in:
lib/rgen/metamodel_builder/build_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NameHelper

#camelize, #className, #firstToLower, #firstToUpper, #normalize, #saneClassName, #saneMethodName

Constructor Details

#initialize(mod, bnd) ⇒ BuildHelper

Returns a new instance of BuildHelper.



16
17
18
19
# File 'lib/rgen/metamodel_builder/build_helper.rb', line 16

def initialize(mod, bnd)
	@outer_binding = bnd
	@mod = mod
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/rgen/metamodel_builder/build_helper.rb', line 23

def method_missing(m, *args)
	if args.empty?
		eval("#{m}",@outer_binding)
	else
		@mod.instance_eval do
			send(m,*args)
		end
	end
end

Class Method Details

.build(mod, bnd, tpl) ⇒ Object



13
14
15
# File 'lib/rgen/metamodel_builder/build_helper.rb', line 13

def self.build(mod,bnd,tpl)
	mod.module_eval ERB.new(tpl).result(BuildHelper.new(mod, bnd).bnd)
end

Instance Method Details

#bndObject



20
21
22
# File 'lib/rgen/metamodel_builder/build_helper.rb', line 20

def bnd
	binding
end

#type_check_code(varname, props) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rgen/metamodel_builder/build_helper.rb', line 32

def type_check_code(varname, props)
	code = ""
	if props.impl_type.is_a?(Class)
		code << "unless #{varname}.nil? or #{varname}.is_a? #{props.impl_type}\n"
		expected = props.impl_type.to_s
	elsif props.impl_type.is_a?(RGen::MetamodelBuilder::DataTypes::Enum)
		code << "unless #{varname}.nil? or [#{props.impl_type.literals_as_strings.join(',')}].include?(#{varname})\n"
	    expected = "["+props.impl_type.literals_as_strings.join(',')+"]"
	else
		raise StandardError.new("Unkown type "+props.impl_type.to_s)
	end
	code << "raise _assignmentTypeError(self,#{varname},\"#{expected}\")\n"
	code << "end"
	code		
end