Class: RbRotate::Reader

Inherits:
Object show all
Defined in:
lib/rb.rotate/reader.rb

Overview

Represents reader of some directory.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ Reader

Constructor.



31
32
33
# File 'lib/rb.rotate/reader.rb', line 31

def initialize(directory)
    @directory = directory
end

Class Method Details

.read(directory, options = { }, &block) ⇒ Object

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



23
24
25
# File 'lib/rb.rotate/reader.rb', line 23

def self.read(directory, options = { }, &block)
    self::new(directory).read(options, &block)
end

Instance Method Details

#read(options = { }, &block) ⇒ Object

Reads the directory content.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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

#stateObject

Returns the state file object.



62
63
64
# File 'lib/rb.rotate/reader.rb', line 62

def state
    State::get
end