Class: RbRotate::Reader
Overview
Represents reader of some directory.
Class Method Summary collapse
-
.read(directory, options = { }, &block) ⇒ Object
Reads the directory.
Instance Method Summary collapse
-
#initialize(directory) ⇒ Reader
constructor
Constructor.
-
#read(options = { }, &block) ⇒ Object
Reads the directory content.
-
#state ⇒ Object
Returns the state file object.
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, = { }, &block) self::new(directory).read(, &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( = { }, &block) filter = [: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 |