class RbRotate::State
Represents state file.
Public Class Methods
archive()
click to toggle source
Alias for archive
.
# File lib/rb.rotate/state.rb, line 72 def self.archive self::get.archive end
each_file(&block)
click to toggle source
Alias for each_file
.
# File lib/rb.rotate/state.rb, line 88 def self.each_file(&block) self::get.each_file(&block) end
files()
click to toggle source
Alias for files
.
# File lib/rb.rotate/state.rb, line 80 def self.files self::get.files end
get()
click to toggle source
Returns self instance.
# File lib/rb.rotate/state.rb, line 52 def self.get if @@self.nil? @@self = self::new end return @@self end
new()
click to toggle source
Constructor.
# File lib/rb.rotate/state.rb, line 44 def initialize @path = self.configuration.paths[:"state file"] end
save!()
click to toggle source
Saves the file. (Shortcut to instance.)
# File lib/rb.rotate/state.rb, line 64 def self.save! self::get.save! end
Public Instance Methods
archive()
click to toggle source
Returns archive accessor instance.
# File lib/rb.rotate/state.rb, line 147 def archive if @archive.nil? @archive = StateModule::Archive::new(self.data[:archive]) end return @archive end
compact!()
click to toggle source
Compacts the file specifications. It removes all empty entries records.
# File lib/rb.rotate/state.rb, line 168 def compact! self.files.reject! do |key, value| value.empty? end end
configuration()
click to toggle source
Returns configuration object instance.
# File lib/rb.rotate/state.rb, line 193 def configuration Configuration::get end
create!()
click to toggle source
Creates new storage.
# File lib/rb.rotate/state.rb, line 127 def create! @data = self.new self.save! end
data()
click to toggle source
Returns data array.
# File lib/rb.rotate/state.rb, line 96 def data if @data.nil? if not ::File.exists? @path self.create! else @data = YAML.load(::File.read(@path)) end end return @data end
each_file() { |path, new(path, data)| ... }
click to toggle source
Traverses through all files and emits path and StateModule::File
objects.
# File lib/rb.rotate/state.rb, line 202 def each_file self.files.each_pair do |path, data| if not data.empty? yield path, StateModule::File::new(path, data) end end end
file(path)
click to toggle source
Returns record for appropriate file.
# File lib/rb.rotate/state.rb, line 178 def file(path) data = self.files[path.to_sym] if data.nil? data = { } self.files[path.to_sym] = data end StateModule::File::new(path, data) end
files()
click to toggle source
Returns files list.
# File lib/rb.rotate/state.rb, line 159 def files self.data[:files] end
new()
click to toggle source
Formats new storage.
# File lib/rb.rotate/state.rb, line 112 def new Hash[ :archive => { :files => { }, :directories => { } }, :files => { }, ] end
save!()
click to toggle source
Saves the file.
# File lib/rb.rotate/state.rb, line 136 def save! self.compact! ::File.open(@path, "w") do |io| io.write(self.data.to_yaml) end end