Module: Iotaz::Persistent

Defined in:
lib/iotaz/Persistent.rb

Constant Summary collapse

@@code =

Module constants.

[%q{@@iotaz_meta_data = Iotaz::IotazMetaData.new(self)},
                %q{def self.class_basename(source)
   name  = source.instance_of?(String) ? source : source.name
   index = name.rindex("::")
   if index != nil
      index += 2
      name  = name[index, name.length - index]
   end
   name
end},
                %q{def self.iotaz_meta_data
    @@iotaz_meta_data
end},
                %q{def self.persistent_attr(name, column=nil, readonly=false)
   attr :"#{name}", true
   private :"#{name}=" if readonly
   name = name.id2name if name.class == Symbol
   attribute = Attribute.new(name, column)
   @@iotaz_meta_data.add_attribute(attribute)
end},
                %q{def self.sequence_attr(name, column=nil, key=true,
                       source=nil, readonly=true,
                       create=true, update=false)
   attr :"#{name}", true
   private :"#{name}=" if readonly
   name = name.id2name if name.class == Symbol
   events = ""
   if create == true and update == false
      events = 'INSERT'
   elsif create == false and update == true
      events = 'UPDATE'
   else
       events = 'INSERT,UPDATE'
   end
   generator = source
   if source == nil
      generator = "#{class_basename(self)}_ID_SQ".upcase
   end
   attribute = GeneratedAttribute.new(name, 'SEQUENCE',
                                      events, generator,
                                      column)
   @@iotaz_meta_data.add_attribute(attribute, key)
end},
                %q{def self.date_attr(name, column=nil, create=true,
                   update=false, value='TODAY',
                   readonly=true)
   attr :"#{name}", true
   private :"#{name}=" if readonly
   name = name.id2name if name.class == Symbol
   events = ""
   if create == true and update == false
      events = 'INSERT'
   elsif create == false and update == true
      events = 'UPDATE'
   else
       events = 'INSERT,UPDATE'
   end
   attribute = GeneratedAttribute.new(name, 'DATE', events,
                                      value, column)
   @@iotaz_meta_data.add_attribute(attribute)
end},
                %q{def self.time_attr(name, column=nil, create=true,
                   update=false, readonly=true)
   attr :"#{name}", true
   private :"#{name}=" if readonly
   name = name.id2name if name.class == Symbol
   events = ""
   if create == true and update == false
      events = 'INSERT'
   elsif create == false and update == true
      events = 'UPDATE'
   else
       events = 'INSERT,UPDATE'
   end
   attribute = GeneratedAttribute.new(name, 'TIME', events,
                                      'NOW', column)
   @@iotaz_meta_data.add_attribute(attribute)
end},
                %q{def self.timestamp_attr(name, column=nil, create=true,
                        update=false, readonly=true)
   attr :"#{name}", true
   private :"#{name}=" if readonly
   name = name.id2name if name.class == Symbol
   events = ""
   if create == true and update == false
      events = 'INSERT'
   elsif create == false and update == true
      events = 'UPDATE'
   else
       events = 'INSERT,UPDATE'
   end
   attribute = GeneratedAttribute.new(name, 'TIMESTAMP',
                                      events, 'NOW', column)
   @@iotaz_meta_data.add_attribute(attribute)
end},
                %q{def self.table_name=(name)
   @@iotaz_meta_data.table = name
end}]

Class Method Summary collapse

Class Method Details

.append_features(target) ⇒ Object

This method gets invoked whenever this module is included into another module or class.

Parameters

target

A reference to the class or module including the Persistent module.



148
149
150
151
152
153
# File 'lib/iotaz/Persistent.rb', line 148

def Persistent.append_features(target)
   super(target)
   @@code.each do |entry|
      target.module_eval(entry)
   end
end

.extend_object(target) ⇒ Object

This method gets invoked whenever this module is used to extend an existing class or module.

Parameters

target

A reference to the class or module that is being extended.



133
134
135
136
137
# File 'lib/iotaz/Persistent.rb', line 133

def Persistent.extend_object(target)
   @@code.each do |entry|
      target.module_eval(entry)
   end
end