class RbRotate::StateModule::File

Represents file state record.

Public Class Methods

new(path, data) click to toggle source

Constructor.

# File lib/rb.rotate/state/file.rb, line 29
def initialize(path, data)
    @path = path
    @data = data
end

Public Instance Methods

create(file) click to toggle source

Creates the state record.

# File lib/rb.rotate/state/file.rb, line 106
def create(file)
    extension = ::File.extname(file.path)[1..-1]
    if extension.nil?
        extension = nil
        cut = 0..-1
    else
        cut = 0..-2
    end
    
    new = {
        :date => Time::now,
        :items => { },
        :directory => file.directory.identifier,
        :filename => {
            :name => ::File.basename(file.path, extension.to_s)[cut],
            :extension => extension
        }
    }
    
    @data.replace(new)
end
date() click to toggle source

Returns last archival date.

# File lib/rb.rotate/state/file.rb, line 46
def date
    @data[:date]
end
destroy!() click to toggle source

Destroys the state record.

# File lib/rb.rotate/state/file.rb, line 132
def destroy!
    State::files.delete(@path.to_sym)
    @data = nil
end
directory() click to toggle source

Returns directory specification.

# File lib/rb.rotate/state/file.rb, line 86
def directory
    if @data.has_key? :directory 
        @data[:directory].to_sym
    else
        nil
    end
end
exists?() click to toggle source

Indicates tate record for file exists.

# File lib/rb.rotate/state/file.rb, line 38
def exists?
    not @data.empty?
end
extension() click to toggle source

Returns extension.

# File lib/rb.rotate/state/file.rb, line 62
def extension
    @data[:filename][:extension]
end
items() click to toggle source

Returns items list.

# File lib/rb.rotate/state/file.rb, line 78
def items
    @data[:items]
end
items=(value) click to toggle source

Sets items list.

# File lib/rb.rotate/state/file.rb, line 98
def items=(value)
    @data[:items].replace(value)
end
name() click to toggle source

Returns basename.

# File lib/rb.rotate/state/file.rb, line 70
def name
    @data[:filename][:name]
end
touch!() click to toggle source

 Touches date to current date.

# File lib/rb.rotate/state/file.rb, line 54
def touch!
    @data[:date] = Time::now
end