Method: ModelClass#require_model_file

Defined in:
lib/model/the_class.rb

#require_model_file(dir = nil) ⇒ Object

requires the file specified in the model-dir

In fact, the model-files are loaded instead of required. Thus, even after recreation of a class (Class.delete_class, ORD.create_class classname) custom methods declared in the model files are present.

If a class is destroyed (i.e. the database class is deleted), the ruby-class and its methods vanish, too.

The directory specified is expanded by the namespace. The parameter itself is the base-dir.

Example:

Namespace:  HC
model_dir : 'lib/model'
searched directory: 'lib/model/hc'

ActiveOrient::Model.modeldir is aimed to be set to the application dir. It may be a String, Pathname or an array of strings or pathnames.

The parameter dir is used internally and by gems to ensure that basic methods are loaded first.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/model/the_class.rb', line 111

def require_model_file  dir = nil
logger.progname = 'ModelClass#RequireModelFile'
# model-dir can either be a string or an array of string or pathnames
default =  [ActiveOrient::Model.model_dir].flatten
# access the default dir's first
the_directories = case dir
									when String, Pathname
									  default.present? ? 	[dir] + default : [dir]
									when Array
										default.present? ? dir + default  : dir
									else
										default.present? ? default : []
									end.uniq.compact
the_directories.uniq.map do |raw_directory|
	the_directory = Pathname( raw_directory )
	if File.exists?( the_directory )
		model= self.to_s.underscore + ".rb"
		filename =   the_directory +  model
		if  File.exists?(filename )
			if load filename
				logger.debug{ "#{filename} sucessfully loaded"  }
				self #return_value
			else
				logger.error{ "#{filename} load error" }
				nil #return_value
			end
		else
			logger.debug{ "model-file not present: #{filename}  --> skipping" }
			nil #return_value
		end
	else
		logger.error{ "Directory #{ the_directory  } not present " }
		nil  #return_value
	end
end.compact.present?  # return true only if at least one model-file is present

rescue TypeError => e
	puts "THE CLASS#require_model_file -> TypeError:  #{e.message}" 
	puts "Working on #{self.to_s} -> #{self.superclass}"
	puts "Class_hierarchy: #{orientdb.class_hierarchy.inspect}."
	print e.backtrace.join("\n") 
	raise
	#
end