class RbRotate::Storage

Represents storage for archived files.

Attributes

directory[R]

Public Class Methods

each_directory() { |get(directory)| ... } click to toggle source

Traverses through all directories in storage.

# File lib/rb.rotate/storage.rb, line 201
def self.each_directory
    Configuration::each_directory do |directory|
        yield self::get(directory)
    end
end
each_entry() { |entry| ... } click to toggle source

Traverses through all entries.

# File lib/rb.rotate/storage.rb, line 187
def self.each_entry
    State::each_file do |path, state|
        file = File::new(path)
        storage = self::new(file.directory)
        entry = StorageModule::Entry::new(storage, file)
        
        yield entry
    end
end
each_item(&block) click to toggle source

Traverses through all items in global storage.

# File lib/rb.rotate/storage.rb, line 177
def self.each_item(&block)
    self.each_entry do |entry|
        entry.each_item(&block)
    end
end
get(directory) click to toggle source

Alias for new.

# File lib/rb.rotate/storage.rb, line 34
def self.get(directory)
    self::new(directory)
end
new(directory) click to toggle source

Constructor.

# File lib/rb.rotate/storage.rb, line 26
def initialize(directory)
    @directory = directory
end
put(file) click to toggle source

Creates storage according to file and puts it to it.

# File lib/rb.rotate/storage.rb, line 42
def self.put(file)
    self::get(file.directory).put(file)
end
remove_orphans!() click to toggle source

Removes orphans.

# File lib/rb.rotate/storage.rb, line 127
def self.remove_orphans!
    self::each_entry do |entry|
        items_count = 0
        
        entry.each_item do |item|
            if item.expired?
                item.remove!
            elsif not item.exists?
                item.unregister!
            else
                items_count += 1
            end
        end
        
        file = entry.file
        if (not file.exists?) and (items_count <= 0)
            file.state.destroy!
        end                    
    end
end

Public Instance Methods

cleanup!() click to toggle source

Cleanups expired items from the storage.

# File lib/rb.rotate/storage.rb, line 101
def cleanup!
    self.each_entry do |entry|
        entry.cleanup!
    end
end
compressed?() click to toggle source

Indicates, storage is compressed.

# File lib/rb.rotate/storage.rb, line 58
def compressed?
    self.directory.compressable?
end
do_actions!(file) click to toggle source

Runs file actions.

# File lib/rb.rotate/storage.rb, line 66
def do_actions!(file)
    entry = StorageModule::Entry::new(self, file)

    # Loads them
    actions = @directory.configuration[:action].split("+")
    actions.map! do |i| 
        i.strip!
        k, v = i.split(":", 2)
        [k.to_sym, v]
    end
    
    # Does them
    variables = { }
    
    actions.each do |action, arguments|
        case action
            when :move, :copy, :append
                variables[:filepath] = entry.put! action
            when :remove
                variables[:filepath] = file.remove!
            when :create, :truncate
                variables[:filepath] = file.create!
            when :mail
                variables[:filepath] = entry.mail! arguments
            when :hook
                name, arguments = arguments.split(":", 2)
                variables.merge! Hook::new(name.to_sym, arguments, variables).run!
        end
    end
end
each_entry() { |entry| ... } click to toggle source

Traverses through all entries of this directory storage.

# File lib/rb.rotate/storage.rb, line 162
def each_entry
    State::each_file do |path, state|
        if state.directory == self.directory.identifier
            file = File::new(path)
            entry = StorageModule::Entry::new(self, file)
            
            yield entry
        end
    end
end
each_item(&block) click to toggle source

Traverses through each item in current storage.

# File lib/rb.rotate/storage.rb, line 152
def each_item(&block)
    self.each_entry do |entry|
        entry.each_item(&block)
    end
end
item_identifier() click to toggle source

Returns item identifier of the storage.

# File lib/rb.rotate/storage.rb, line 111
def item_identifier
    self.directory.configuration[:identifier]
end
numeric_identifier?() click to toggle source

Indicates numeric identifier.

# File lib/rb.rotate/storage.rb, line 119
def numeric_identifier?
    self.item_identifier.to_sym == :numeric
end
put(file) click to toggle source

 Puts file to storage.

# File lib/rb.rotate/storage.rb, line 50
def put(file)
    self.do_actions! file
end