Class: RbRotate::StateModule::File
- Defined in:
- lib/rb.rotate/state/file.rb
Overview
Represents file state record.
Instance Method Summary collapse
-
#create(file) ⇒ Object
Creates the state record.
-
#date ⇒ Object
Returns last archival date.
-
#destroy! ⇒ Object
Destroys the state record.
-
#directory ⇒ Object
Returns directory specification.
-
#exists? ⇒ Boolean
Indicates tate record for file exists.
-
#extension ⇒ Object
Returns extension.
-
#initialize(path, data) ⇒ File
constructor
Constructor.
-
#items ⇒ Object
Returns items list.
-
#items=(value) ⇒ Object
Sets items list.
-
#name ⇒ Object
Returns basename.
-
#touch! ⇒ Object
Touches date to current date.
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 |
#date ⇒ Object
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 |
#directory ⇒ Object
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.
38 39 40 |
# File 'lib/rb.rotate/state/file.rb', line 38 def exists? not @data.empty? end |
#extension ⇒ Object
Returns extension.
62 63 64 |
# File 'lib/rb.rotate/state/file.rb', line 62 def extension @data[:filename][:extension] end |
#items ⇒ Object
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 |
#name ⇒ Object
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 |