Sha256: e72ca0c27022d5a93abe807394eb24698ae64d59d9ed79b2725e1395c252b70d

Contents?: true

Size: 1010 Bytes

Versions: 229

Compression:

Stored size: 1010 Bytes

Contents

# RGen Framework
# (c) Martin Thiede, 2006

require 'rgen/metamodel_builder'

module RGen

module Util

class Base
	extend MetamodelBuilder
	def initialize(env=nil)
		env << self if env
	end
end

class AutoCreatedClass < Base
	def method_missing(m,*args)
		return super unless self.class.parent.accEnabled
		if m.to_s =~ /(.*)=$/ 
			self.class.has_one($1)
			send(m,args[0])
		elsif args.size == 0
			self.class.has_many(m)
			send(m)
		end
	end
end

# will be "extended" to the auto created class
module ParentAccess
	def parent=(p)
		@parent = p
	end
	def parent
		@parent
	end
end

module AutoClassCreator
	attr_reader :accEnabled
	def const_missing(className)
		return super unless @accEnabled
		module_eval("class "+className.to_s+" < RGen::AutoCreatedClass; end")
		c = const_get(className)
		c.extend(ParentAccess)
		c.parent = self
		c
	end
	def enableACC
		@accEnabled = true
	end
	def disableACC
		@accEnabled = false
	end
end

end

end

Version data entries

229 entries across 229 versions & 3 rubygems

Version Path
rgen-0.10.2 lib/rgen/util/auto_class_creator.rb
rgen-0.10.0 lib/rgen/util/auto_class_creator.rb
rgen-0.9.1 ./lib/rgen/util/auto_class_creator.rb
rgen-0.8.3 lib/rgen/util/auto_class_creator.rb
rgen-0.8.4 lib/rgen/util/auto_class_creator.rb
rgen-0.9.0 lib/rgen/util/auto_class_creator.rb
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.12 lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.12-x86-mingw32 lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.12-x64-mingw32 lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.12-universal-darwin lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.11 lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.11-x86-mingw32 lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.11-x64-mingw32 lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.11-universal-darwin lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.10 lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.10-x86-mingw32 lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.10-x64-mingw32 lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb
puppet-4.10.10-universal-darwin lib/puppet/vendor/rgen/lib/rgen/util/auto_class_creator.rb