Class: RbRotate::Directory
Overview
Represents one log directory.
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#path ⇒ Object
readonly
Returns path to directory.
Instance Method Summary collapse
-
#compressable? ⇒ Boolean
Indicates, directory entries should be compressed in archive.
-
#configuration ⇒ Object
Returns the configuration instance.
-
#configured? ⇒ Boolean
Indicates, it isn’t child directory of configured directory, but directly the configured directory.
-
#configured_ancestor ⇒ Object
Returns the “nearest” configured ancestor.
-
#each_directory(&block) ⇒ Object
Traverses through all directories in directory.
-
#each_file(&block) ⇒ Object
Traverses through all files in directory.
-
#initialize(identifier, parent = nil) ⇒ Directory
constructor
Constructor.
-
#relative_path ⇒ Object
Returns relative path to parent (configured) directory.
-
#rotate! ⇒ Object
Rotates.
-
#storage ⇒ Object
Returns storage appropriate to directory.
Constructor Details
#initialize(identifier, parent = nil) ⇒ Directory
Constructor.
Identifier is symbol so identifier in configuration file or string, so directory path.
56 57 58 59 60 61 62 63 |
# File 'lib/rb.rotate/directory.rb', line 56 def initialize(identifier, parent = nil) @parent = parent if identifier.kind_of? Symbol @identifier = identifier else @path = identifier end end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
40 41 42 |
# File 'lib/rb.rotate/directory.rb', line 40 def identifier @identifier end |
#path ⇒ Object (readonly)
Returns path to directory.
So it get @path or directory from configuration if hasn’t been sete.
113 114 115 |
# File 'lib/rb.rotate/directory.rb', line 113 def path @path end |
Instance Method Details
#compressable? ⇒ Boolean
Indicates, directory entries should be compressed in archive.
187 188 189 |
# File 'lib/rb.rotate/directory.rb', line 187 def compressable? not self.configuration[:compress].nil? end |
#configuration ⇒ Object
Returns the configuration instance.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rb.rotate/directory.rb', line 69 def configuration if @configuration.nil? # If no identifier set, looks for the dir # in configuration. if @identifier.nil? directory = Configuration::find_path(@path) if not directory.nil? @identifier = directory.identifier @configured = true elsif not @parent.nil? @identifier = @parent.identifier @configured = false else @identifier = :default @configured = false end else @configured = true end @configuration = DirectoryConfiguration::new(@identifier) end return @configuration end |
#configured? ⇒ Boolean
Indicates, it isn’t child directory of configured directory, but directly the configured directory.
101 102 103 104 |
# File 'lib/rb.rotate/directory.rb', line 101 def configured? self.configuration @configured end |
#configured_ancestor ⇒ Object
Returns the “nearest” configured ancestor.
137 138 139 140 141 142 143 144 145 |
# File 'lib/rb.rotate/directory.rb', line 137 def configured_ancestor if self.configured? self elsif not @parent.nil? @parent.configured_ancestor else nil end end |
#each_directory(&block) ⇒ Object
Traverses through all directories in directory.
159 160 161 |
# File 'lib/rb.rotate/directory.rb', line 159 def each_directory(&block) Reader::read(self, :filter => :dirs, &block) end |
#each_file(&block) ⇒ Object
Traverses through all files in directory.
151 152 153 |
# File 'lib/rb.rotate/directory.rb', line 151 def each_file(&block) Reader::read(self, :filter => :files, &block) end |
#relative_path ⇒ Object
Returns relative path to parent (configured) directory.
125 126 127 128 129 130 131 |
# File 'lib/rb.rotate/directory.rb', line 125 def relative_path if self.configured? "." else self.path[(self.configured_ancestor.path.length + 1)..-1] end end |
#rotate! ⇒ Object
Rotates.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rb.rotate/directory.rb', line 167 def rotate! # Cleans old or expired items # self.storage.cleanup! (cleaned up globally by dispatcher call) # Rotates if self.configuration[:recursive] self.each_directory do |directory| directory.rotate! end end self.each_file do |file| file.rotate! end end |