-------------------------------------------------------------------------------- -- Title: LUPUser.lua -- Description: Like a square peg in a round hole -- Author: Raphaël Szwarc http://alt.textdrive.com/lua/ -- Creation Date: February 1, 2005 -- Legal: Copyright (C) 2005 Raphaël Szwarc -------------------------------------------------------------------------------- -- import dependencies require( "LUObject" ) require( "LFSFile" ) require( "LUPTimeline" ) require( "LUPIndex" ) -- extend the super class local thisClass, superClass = LUObject.extend( LUObject ) -- class variables local cvars = {} -- factory class method, this is where all the instance methods are implemented as closures thisClass.new = function( aName ) -- extend the super class instance local this = superClass.extend( superClass.new() ) -- instance variables local ivars = { name = aName } -- instance method this.address = function() return "\"" .. this.name() .. "\" <" .. this.name() .. "@" .. this.host() .. ">" end -- instance method this.name = function() return ivars.name end -- private instance method local path = function() local aSeparator = LFSFile.separator() local aPath = "." aPath = aPath .. aSeparator aPath = aPath .. "lupad" aPath = aPath .. aSeparator aPath = aPath .. this.name() return aPath end -- instance method this.directory = function() if ( ivars.directory == nil ) then local aDirectory = LFSFile.new( path() ) if ( aDirectory.exists() == false ) then aDirectory.mkdirs() end ivars.directory = aDirectory end return ivars.directory end -- instance method to compare the given object with this object for equality this.equals = function( anObject ) if ( this == anObject ) then return true end if ( this.isKindOf( anObject, this ) == true ) then if ( this.name() == anObject.name() ) then return true end end return false end -- instance method this.host = function() return "localhost.local" end -- instance method this.noteDidChange = function( aNote, aPreviousID ) LULog.debug( aNote ) LULog.debug( aNote.id() ) LULog.debug( aPreviousID ) do local aValue = aNote.subject() .. " " .. aNote.content() local anID = aNote.id() this.index().updateValueWithKey( aValue, anID, aPreviousID ) end return this end -- instance method this.index = function() if ( ivars.index == nil ) then ivars.index = LUPIndex.new( this ) end return ivars.index end -- instance method this.timeline = function() if ( ivars.timeline == nil ) then ivars.timeline = LUPTimeline.new( this ) end return ivars.timeline end -- instance method this.toString = function() return this.name() end -- return the public instance methods return superClass.inherit( this ) end -- class method thisClass.default = function() if ( cvars.default == nil ) then local aName = string.lower( os.getenv( "USER" ) ) cvars.default = thisClass.new( aName ) end return cvars.default end -- define the class name LUPUser = thisClass return LUPUser