Module: Kernel

Defined in:
lib/ontomde-core/meta.rb,
lib/ontomde-core/inspector.rb

Instance Method Summary collapse

Instance Method Details

#model_for_inspectorObject



4
5
6
# File 'lib/ontomde-core/inspector.rb', line 4

def model_for_inspector
  return @@model_for_inspector
end

#rdf_attr(sym, range) ⇒ Object

creates rdf attribute and accessors



227
228
229
230
231
# File 'lib/ontomde-core/meta.rb', line 227

def rdf_attr(sym,range)
  rdf_attr_rubyCode(sym,range).each { |code|
    class_eval code
  }
end

#rdf_attr_rubyCode(sym, range) ⇒ Object

returns ruby code generated for rdf attribute and accessors.



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/ontomde-core/meta.rb', line 234

def rdf_attr_rubyCode(sym,range)
  ret=[]
  # TODO: ne pas crer un objet vide systématiquement.

  #sym_array=sym.to_s.split("_",3)
  #sym_short=""
  #if sym_array[0]=="uml" && sym_array[2]!=""
  #	sym_short="#{sym_array[0]}_#{sym_array[2]}"
  #else
  sym_short=sym
  #end
  #version normale
  #TODO: supprimer la version normale
  #      ou raccourcir les nom en amont
  #class_eval %{def #{sym}
  #	log.warn "method #{sym} is deprecated. Use #{sym_short} instead"
  #	@#{sym}.nil? ? ::ArrayOrSingleElementEmpty.instance : @#{sym}
  #end}
  #version courte

  #log.debug "sym_short: >#{sym_array[0]}< >#{sym_array[1]}< >#{sym_array[2]}<"
  #log.debug sym_short
  ret << %{def #{sym_short}
	@#{sym}.nil? ? ::ArrayOrSingleElementEmpty.instance : @#{sym}
end}

  (range.empty?&&true ? [Crdf_Resource] : range).each { |inv_res|
    next if inv_res==::Mrdfs_Literal
    inv_res.class_eval <<END
def #{sym_short}_inv
	return rdf_getter_inv(:#{sym_short}) { |g| g.#{sym_short} }
end
def #{sym_short}_inv_one()
	return rdf_getter_one(#{sym_short}_inv,true,:#{sym_short}_inv)
end
def #{sym_short}_inv_one0()
	return rdf_getter_one(#{sym_short}_inv,false,:#{sym_short}_inv)
end
END
  }


  range_array='['; sep=''
  range.each { |r|
    range_array+=sep+r.name #.getRubyModuleName
    sep=','
  }
  range_array+=']'

  if (true)
    ret << %{def #{sym_short}_typeOk?(val)
		check_rdfType(#{range_array},val,:#{sym_short},self)
	end
    }
  else
    # TODO: more performant but generates warnings
    # investigate reason of multiple execution
    ret << %{RANGE_#{sym_short}=#{range_array}
	def #{sym_short}_typeOk?(val)
		check_rdfType(RANGE_#{sym_short},val,:#{sym_short},self)
	end
    }
  end

  ret <<  %{def #{sym_short}?
	return #{sym_short}.isTrue?
end}

  ret << %{def #{sym_short}_one()
	return rdf_getter_one(@#{sym},true,:#{sym_short})
end}

  ret << %{def #{sym_short}_one0()
	return rdf_getter_one(@#{sym},false,:#{sym_short})
end}

  inv=(sym_short.to_s=='ext_isReferencedBy') ? '' : 'item.ext_isReferencedBy_add(self) if item.respond_to?(:ext_isReferencedBy_add) '

  ret << %{def #{sym_short}=(v)
	if v.nil?
		@#{sym}=nil
	elsif  v.kind_of?(ArrayOrSingleElement) || v.kind_of?(Array) || v.kind_of?(ArrayOrSingleElementEmpty)
		@#{sym}= ArrayOrSingleElement.new
		v.each { |item|
			#{sym_short}_typeOk?(item)
  @#{sym}.push(item)
  #{inv}
			}
	else
		@#{sym}= ArrayOrSingleElement.new
		#{sym_short}_typeOk?(v)
		@#{sym}.push(v)
		item=v
		#{inv}
	end
end}

  ret << %{def #{sym_short}_add(item)
	if !item.nil?
		#log.debug @#{sym}.size+1000
		if @#{sym}.nil?
			#log.debug "reset @#{sym}"
			@#{sym}= ArrayOrSingleElement.new
		end
		#{sym_short}_typeOk?(item)
		@#{sym}.push(item)
		#{inv}
	end
end}

  return ret
end

#rdf_safe_attr_reader_many(*syms) ⇒ Object

Creates accessors for rdf property passed as argument.

Example:

for rdf_safe_attr_reader_many uml_abcde_efgh
the following methods are generated

def uml_abcd_efgh ()
  returns an Array of reference elements.
  (This array is READ-ONLY)

def uml_efgh ()
  same as uml_abcd_efgh
  in case of name clashing use long version.

def uml_efgh_one()
   Returns nil if array is empty
   Triggers an error if array contains more than one element.
   returns the first element of array

def uml_efgh=(x)
   reset array and add x

def uml_efgh_add(x)
   add x to the existing array

def uml_efgh?
   returns uml_efgh.isTrue?()


218
219
220
221
222
223
224
# File 'lib/ontomde-core/meta.rb', line 218

def rdf_safe_attr_reader_many(*syms)
  syms.each { |s|
    rdf_attr_rubyCode(s,[]).each { |code|
      class_eval code
    }
  }
end

#set_model_for_inspector(model) ⇒ Object



7
8
9
# File 'lib/ontomde-core/inspector.rb', line 7

def set_model_for_inspector(model)
  @@model_for_inspector=model
end