class Dutiful::ApplicationFile
Attributes
path[R]
Public Class Methods
new(path, condition)
click to toggle source
# File lib/dutiful/application_file.rb, line 4 def initialize(path, condition) @condition, @path = condition, path end
Public Instance Methods
backup()
click to toggle source
# File lib/dutiful/application_file.rb, line 8 def backup Dutiful::Config.storage.backup self end
backup_path()
click to toggle source
# File lib/dutiful/application_file.rb, line 16 def backup_path Dutiful::Config.storage.path path end
backup_timestamp()
click to toggle source
# File lib/dutiful/application_file.rb, line 20 def backup_timestamp File.mtime backup_path if has_backup? end
command()
click to toggle source
# File lib/dutiful/application_file.rb, line 24 def command @condition[:command] if has_condition? end
directory?()
click to toggle source
# File lib/dutiful/application_file.rb, line 52 def directory? path.chars.last == '/' end
exist?()
click to toggle source
# File lib/dutiful/application_file.rb, line 56 def exist? File.exist?(full_path) && meets_conditions? end
expected_output()
click to toggle source
# File lib/dutiful/application_file.rb, line 28 def expected_output @condition[:expected_output] if has_condition? end
expected_status()
click to toggle source
# File lib/dutiful/application_file.rb, line 32 def expected_status @condition[:expected_status] if has_condition? end
full_path()
click to toggle source
# File lib/dutiful/application_file.rb, line 36 def full_path if directory? "#{File.expand_path "~/#{path}"}/" else File.expand_path "~/#{path}" end end
has_backup?()
click to toggle source
# File lib/dutiful/application_file.rb, line 60 def has_backup? Dutiful::Config.storage.exist?(self) && meets_conditions? end
has_condition?()
click to toggle source
# File lib/dutiful/application_file.rb, line 64 def has_condition? @condition end
in_sync?()
click to toggle source
# File lib/dutiful/application_file.rb, line 86 def in_sync? has_backup? && Dutiful::Config.storage.in_sync?(self) end
meets_conditions?()
click to toggle source
# File lib/dutiful/application_file.rb, line 68 def meets_conditions? if has_condition? output = `#{command}`.strip if expected_status $?.exitstatus == expected_status else $?.success? && output == expected_output end else true end end
name()
click to toggle source
# File lib/dutiful/application_file.rb, line 44 def name path end
restore()
click to toggle source
# File lib/dutiful/application_file.rb, line 12 def restore Dutiful::Config.storage.restore self end
timestamp()
click to toggle source
# File lib/dutiful/application_file.rb, line 48 def timestamp File.mtime full_path if exist? end
to_s()
click to toggle source
# File lib/dutiful/application_file.rb, line 90 def to_s return "#{path} does not meet conditions (skipping)".yellow unless meets_conditions? if exist? if has_backup? if in_sync? "#{path} ✔".green else "#{path} (modified)".yellow end else "#{path} (pending backup)".yellow end elsif has_backup? "#{path} (pending restore)".yellow else "#{path} does not exist (skipping)".light_black end end
tracked?()
click to toggle source
# File lib/dutiful/application_file.rb, line 82 def tracked? exist? || has_backup? end