class RbRotate::Reader

Represents reader of some directory.

Public Class Methods

new(directory) click to toggle source

Constructor.

# File lib/rb.rotate/reader.rb, line 31
def initialize(directory)
    @directory = directory
end
read(directory, options = { }, &block) click to toggle source

Reads the directory. (Shortcut for non-static read.) Create new instance and call read.

# File lib/rb.rotate/reader.rb, line 23
def self.read(directory, options = { }, &block)
    self::new(directory).read(options, &block)
end

Public Instance Methods

read(options = { }, &block) click to toggle source

Reads the directory content.

# File lib/rb.rotate/reader.rb, line 39
def read(options = { }, &block)
    filter = options[:filter]

    dirpath = @directory.path
    Dir.open(dirpath) do |dir|
        dir.each_entry do |item|
            filepath = dirpath.dup << "/" << item
            
            if (not @directory.configuration[:follow]) and (::File.symlink? filepath)
                next
            elsif (filter.nil? or (filter == :files)) and (::File.file? filepath)
                emit_file filepath, &block
            elsif (filter.nil? or (filter == :dirs)) and (item != ?.) and (item.to_sym != :"..") and (::File.directory? filepath)
                emit_directory filepath, &block
            end
        end
    end
end
state() click to toggle source

Returns the state file object.

# File lib/rb.rotate/reader.rb, line 62
def state
    State::get
end

Private Instance Methods

emit_directory(filepath) { |new(filepath, directory)| ... } click to toggle source

Emits directory.

# File lib/rb.rotate/reader.rb, line 84
def emit_directory(filepath)
    if not self.state.archive.has_directory? filepath
        yield Directory::new(filepath, @directory)
    end
end
emit_file(filepath) { |new(filepath, directory)| ... } click to toggle source

Emits file.

# File lib/rb.rotate/reader.rb, line 74
def emit_file(filepath)
    if not self.state.archive.has_file? filepath
        yield File::new(filepath, @directory)
    end
end