class Dutiful::Application

Public Class Methods

all() click to toggle source
# File lib/dutiful/application.rb, line 52
def self.all
  Dir["#{Dutiful.dir}/db/*.toml"].map do |filename|
    Dutiful::Application.new filename
  end.compact
end
each() { |application| ... } click to toggle source
# File lib/dutiful/application.rb, line 58
def self.each
  return enum_for(:each) unless block_given?

  all.each { |application| yield application }
end
new(path) click to toggle source
# File lib/dutiful/application.rb, line 2
def initialize(path)
  @path = path
end

Public Instance Methods

backup() { |file, backup| ... } click to toggle source
# File lib/dutiful/application.rb, line 20
def backup(&block)
  (files + defaults).each do |file|
    if file.exist?
      yield file, file.backup if block_given?
    else
      yield file if block_given?
    end
  end
end
defaults() click to toggle source
# File lib/dutiful/application.rb, line 6
def defaults
  return [] unless Dutiful::Config.osx?

  Array(content[:default]).map { |default| Dutiful::ApplicationDefault.new default }
end
exist?() click to toggle source
# File lib/dutiful/application.rb, line 40
def exist?
  files.any?(&:exist?) || defaults.any?(&:exist?)
end
files() click to toggle source
# File lib/dutiful/application.rb, line 12
def files
  Array(content[:file]).map { |file| Dutiful::ApplicationFile.new file[:path], file[:condition] }
end
has_backup?() click to toggle source
# File lib/dutiful/application.rb, line 44
def has_backup?
  files.any?(&:has_backup?) || defaults.any?(&:has_backup?)
end
name() click to toggle source
# File lib/dutiful/application.rb, line 16
def name
  content[:application][:name]
end
restore() { |file, restore| ... } click to toggle source
# File lib/dutiful/application.rb, line 30
def restore(&block)
  (files + defaults).each do |file|
    if file.has_backup?
      yield file, file.restore if block_given?
    else
      yield file if block_given?
    end
  end
end
tracked?() click to toggle source
# File lib/dutiful/application.rb, line 48
def tracked?
  exist? || has_backup?
end

Private Instance Methods

content() click to toggle source
# File lib/dutiful/application.rb, line 66
def content
  @content ||= Tomlrb.load_file(@path, symbolize_keys: true)
end