Sha256: bf14a870c60147833231efbbe81b070f26cd7deca4277796ff417cda047019ad
Contents?: true
Size: 1.55 KB
Versions: 9
Compression:
Stored size: 1.55 KB
Contents
module UniverseCompiler module Entity module FieldManagement private def define_known_fields_accessors self.class.fields_constraints.each do |field_name, constraints| define_field_accessor field_name if fields[field_name].nil? fields[field_name] = [] if constraints[:has_many] || constraints[:is_array] fields[field_name] = {} if constraints[:is_hash] end end end def define_field_accessor(field_name) metaclass = class << self; self ; end UniverseCompiler.logger.debug 'Defining field accessor %s on class %s (%s)' % [field_name, metaclass, self.type] define_field_reader(field_name, metaclass) define_field_writer(field_name, metaclass) end def define_field_writer(field_name, metaclass) if self.respond_to? "#{field_name}=" UniverseCompiler.logger.info "'#{field_name}=' already exists on class '#{metaclass}'. Skipped !" else metaclass.instance_eval do define_method "#{field_name}=" do |value| fields[field_name] = value end end end end def define_field_reader(field_name, metaclass) if self.respond_to? field_name UniverseCompiler.logger.info "'#{field_name}' already exists on class '#{metaclass}'. Skipped !" else metaclass.instance_eval do define_method field_name do fields[field_name] end end end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems