Sha256: 804357c56802d62082ee1d90768cc5e0dd800d0722f092e416a9b2690c6c84c5

Contents?: true

Size: 1.6 KB

Versions: 6

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = FileList.rb -- The TaskJuggler III Project Management Software
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011
#               by Chris Schlaeger <chris@linux.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#

class TaskJuggler

  # The FileRecord stores the name of a file and the modification time.
  class FileRecord

    def initialize(fileName)
      @name = fileName.dup.untaint
      @mtime = File.mtime(@name)
    end

    def modified?
      File.mtime(@name) > @mtime
    end

  end

  # The FileList class stores a list of file names. Each file name is unique
  # and more information about the file is contained in FileRecord entries.
  class FileList

    # Create a new, empty FileList.
    def initialize
      @files = {}
    end

    # Add the file with _fileName_ to the list. If it's already in the list,
    # it will not be added again.
    def <<(fileName)
      return if fileName == '.' || @files.include?(fileName)

      @files[fileName] = FileRecord.new(fileName)
    end

    # Return the name of the master file or nil of the master file was stdin.
    def masterFile
      @files.each_key do |file|
        return file if file[-4, 4] == '.tjp'
      end

      nil
    end

    # Return true if any of the files in the list have been modified after
    # they were added to the list.
    def modified?
      @files.each_value do |f|
        return true if f.modified?
      end
      false
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
taskjuggler-3.0.0 lib/taskjuggler/FileList.rb
taskjuggler-0.2.2 lib/taskjuggler/FileList.rb
taskjuggler-0.2.1 lib/taskjuggler/FileList.rb
taskjuggler-0.2.0 lib/taskjuggler/FileList.rb
taskjuggler-0.1.1 lib/taskjuggler/FileList.rb
taskjuggler-0.1.0 lib/taskjuggler/FileList.rb