Class: RbRotate::StateModule::File

Inherits:
Object
  • Object
show all
Defined in:
lib/rb.rotate/state/file.rb

Overview

Represents file state record.

Instance Method Summary collapse

Constructor Details

#initialize(path, data) ⇒ File

Constructor.



29
30
31
32
# File 'lib/rb.rotate/state/file.rb', line 29

def initialize(path, data)
    @path = path
    @data = data
end

Instance Method Details

#create(file) ⇒ Object

Creates the state record.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 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

#dateObject

Returns last archival date.



46
47
48
# File 'lib/rb.rotate/state/file.rb', line 46

def date
    @data[:date]
end

#destroy!Object

Destroys the state record.



132
133
134
135
# File 'lib/rb.rotate/state/file.rb', line 132

def destroy!
    State::files.delete(@path.to_sym)
    @data = nil
end

#directoryObject

Returns directory specification.



86
87
88
89
90
91
92
# 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?Boolean

Indicates tate record for file exists.

Returns:

  • (Boolean)


38
39
40
# File 'lib/rb.rotate/state/file.rb', line 38

def exists?
    not @data.empty?
end

#extensionObject

Returns extension.



62
63
64
# File 'lib/rb.rotate/state/file.rb', line 62

def extension
    @data[:filename][:extension]
end

#itemsObject

Returns items list.



78
79
80
# File 'lib/rb.rotate/state/file.rb', line 78

def items
    @data[:items]
end

#items=(value) ⇒ Object

Sets items list.



98
99
100
# File 'lib/rb.rotate/state/file.rb', line 98

def items=(value)
    @data[:items].replace(value)
end

#nameObject

Returns basename.



70
71
72
# File 'lib/rb.rotate/state/file.rb', line 70

def name
    @data[:filename][:name]
end

#touch!Object

 Touches date to current date.



54
55
56
# File 'lib/rb.rotate/state/file.rb', line 54

def touch!
    @data[:date] = Time::now
end