Class: Dutiful::ApplicationFile

Inherits:
Object
  • Object
show all
Defined in:
lib/dutiful/application_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ApplicationFile

Returns a new instance of ApplicationFile.



4
5
6
7
# File 'lib/dutiful/application_file.rb', line 4

def initialize(path)
  @path      = path
  @full_path = File.expand_path "~/#{path}"
end

Instance Attribute Details

#full_pathObject (readonly)

Returns the value of attribute full_path.



2
3
4
# File 'lib/dutiful/application_file.rb', line 2

def full_path
  @full_path
end

#pathObject (readonly)

Returns the value of attribute path.



2
3
4
# File 'lib/dutiful/application_file.rb', line 2

def path
  @path
end

Instance Method Details

#backup_pathObject



9
10
11
# File 'lib/dutiful/application_file.rb', line 9

def backup_path
  Dutiful::Config.storage.path path
end

#backup_timestampObject



13
14
15
# File 'lib/dutiful/application_file.rb', line 13

def backup_timestamp
  File.mtime backup_path if has_backup?
end

#exist?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/dutiful/application_file.rb', line 21

def exist?
  File.exist? full_path
end

#has_backup?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/dutiful/application_file.rb', line 25

def has_backup?
  Dutiful::Config.storage.exist? self
end

#synced?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/dutiful/application_file.rb', line 29

def synced?
  has_backup? && Dutiful::Config.storage.synced?(self)
end

#timestampObject



17
18
19
# File 'lib/dutiful/application_file.rb', line 17

def timestamp
  File.mtime full_path if exist?
end

#to_sObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dutiful/application_file.rb', line 33

def to_s
  if exist?
    return "#{path} ✔".green if synced?

    if has_backup?
      return "#{path} (modified)".yellow
    else
      return "#{path} (pending backup)".yellow
    end
  end

  "#{path} (pending restore)".yellow if has_backup?
end