class RbRotate::StorageModule::Entry
Represents an entry of the storage. Entry
is archived items of one file.
Attributes
file[R]
storage[R]
Public Class Methods
new(storage, file)
click to toggle source
Constructor.
# File lib/rb.rotate/storage/entry.rb, line 34 def initialize(storage, file) @storage = storage @file = file end
Public Instance Methods
cleanup!()
click to toggle source
Cleanups the items.
# File lib/rb.rotate/storage/entry.rb, line 75 def cleanup! self.each_item do |item| if item.expired? item.remove! end end end
each_item() { |new(self, identifier, path)| ... }
click to toggle source
Traverses through all items.
# File lib/rb.rotate/storage/entry.rb, line 112 def each_item self.file.state.items.each_pair do |identifier, path| yield Item::new(self, identifier, path) end end
mail!(to)
click to toggle source
Mail
file to specified address.
# File lib/rb.rotate/storage/entry.rb, line 87 def mail!(to) if to.nil? to = @storage.directory.configuration[:mail] end if to.nil? raise Exception("No e-mail address specified for sending log to.") end require "etc" require "socket" Mail::send( :from => Etc.getlogin.dup << "@" << Socket.gethostname, :to => to, :subject => Socket.gethostname.dup << " : log : " << self.file.path, :body => ::File.read(self.file.path) ) return self.file.path end
put!(method)
click to toggle source
Puts current version of the file to items.
# File lib/rb.rotate/storage/entry.rb, line 43 def put!(method) # If necessary, creates the state record if not self.file.state.exists? self.file.state.create(@file) end # Rotates other items new_list = { } self.each_item do |item| if item.exists? item.rotate! new_list[item.identifier] = item.path else item.unregister! end end # Puts new item item = Item::new(self).allocate(method) new_list[item.identifier] = item.path self.file.state.touch! self.file.state.items = new_list return self.file.path end