class DeployLog::Cache

Attributes

filename[R]

Public Class Methods

new(fmt, options = {}) click to toggle source
# File lib/deploy_log/cache.rb, line 11
def initialize(fmt, options = {})
  fmt ||= 'deploy_%s.log'
  dir = options[:dir] || '/tmp'

  @repo = options[:repo]
  @file_name_template = "#{dir}/#{fmt}"
end

Public Instance Methods

contents() click to toggle source
# File lib/deploy_log/cache.rb, line 30
def contents
  raise FileNotFound unless exists?

  File.read(@filename)
end
create(*args) click to toggle source
# File lib/deploy_log/cache.rb, line 19
def create(*args)
  hash = Digest::MD5.hexdigest(@repo + args.join('|'))
  path = FileUtils.touch format(@file_name_template, hash)

  @filename = path.first
end
exists?() click to toggle source
# File lib/deploy_log/cache.rb, line 26
def exists?
  File.exist?(@filename) && !File.size(@filename).zero?
end
write_object(pool, message) { |pr| ... } click to toggle source
# File lib/deploy_log/cache.rb, line 36
def write_object(pool, message)
  File.open(@filename, 'w+') do |file|
    pool.each do |pr|
      line = yield(pr)

      file.write(line)
    end

    file.write "============================================================\n"
    file.write "#{message}\n"
    file.write "============================================================\n"
  end
end