class Module

Public Instance Methods

configuration() click to toggle source

configure adds the options method to a class which allows it to access the global configuration hash.

name

an arrays of symbols representing the attributes on the object.

# File lib/utility/configuration.rb, line 51
  def configuration()
    class_eval "      def options
        Configuration.instance.options
      end
"
  end
logger(loglevel='DEBUG', logto=['stderr','server']) click to toggle source

logger defines a named log and log method for the class

loglevel

the level of logging to do

# File lib/utility/log.rb, line 53
  def logger(loglevel='DEBUG', logto=['stderr','server'])
    class_eval "      @log = Log.instance.loginit(self.name, "#{loglevel}", #{logto.inspect})
      def log
        self.class.instance_variable_get :@log
      end
"
  end
property(*sym) click to toggle source

Properties modifies class Module by adding the property method which:

  1. creates read/write accessors for each symbol.

  2. defines the to_yaml_properties for use by the database for all symbols.

  3. defines the :id attribute

sym

an arrays of symbols representing the attributes on the object.

# File lib/storage/properties.rb, line 26
  def property(*sym)
    if Configuration.instance.options['props_are_accessors_only']
      attr_accessor(*sym)
      class_eval <<-EOD
        def id
          @id ||= Engine.instance.db.getid
        end
      EOD
      return
    end
    sym.each do |s|
      class_eval "        def #{s}
          @props ||= {}
          if options['safe_read'] && !@props[:#{s}].kind_of?(Numeric)
            Engine.instance.db.mark(self.id)
            @props[:updated_on] = Time.now
          end
          @props[:#{s}]
        end
        def #{s}=(val)
          @props ||= {}
          Engine.instance.db.mark(self.id)
          @props[:updated_on] = Time.now
          @props[:#{s}] = val
        end
"
    end
    class_eval "      def to_yaml_properties
        ['@props']
      end
      def id
        @props ||= {}
        @props[:id] ||= Engine.instance.db.getid
      end
      def _dump(depth)
        Marshal.dump(@props)
      end
      def self._load(str)
        obj = allocate
        obj.instance_variable_set(:@props,Marshal.load(str))
        obj
      end
"
  end