Class: Dutiful::ApplicationFile
- Inherits:
-
Object
- Object
- Dutiful::ApplicationFile
- Defined in:
- lib/dutiful/application_file.rb
Instance Attribute Summary collapse
-
#full_path ⇒ Object
readonly
Returns the value of attribute full_path.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #backup_path ⇒ Object
- #backup_timestamp ⇒ Object
- #directory? ⇒ Boolean
- #exist? ⇒ Boolean
- #has_backup? ⇒ Boolean
- #has_condition? ⇒ Boolean
-
#initialize(path, condition) ⇒ ApplicationFile
constructor
A new instance of ApplicationFile.
- #meets_conditions? ⇒ Boolean
- #should_sync? ⇒ Boolean
- #synced? ⇒ Boolean
- #timestamp ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path, condition) ⇒ ApplicationFile
Returns a new instance of ApplicationFile.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/dutiful/application_file.rb', line 4 def initialize(path, condition) @command = condition[:command] if condition @expected_output = condition[:expected_output] if condition @expected_status = condition[:expected_status] if condition @path = path if directory? @full_path = "#{File. "~/#{path}"}/" else @full_path = File. "~/#{path}" end end |
Instance Attribute Details
#full_path ⇒ Object (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 |
#path ⇒ Object (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_path ⇒ Object
17 18 19 |
# File 'lib/dutiful/application_file.rb', line 17 def backup_path Dutiful::Config.storage.path path end |
#backup_timestamp ⇒ Object
21 22 23 |
# File 'lib/dutiful/application_file.rb', line 21 def File.mtime backup_path if has_backup? end |
#directory? ⇒ Boolean
43 44 45 |
# File 'lib/dutiful/application_file.rb', line 43 def directory? path.chars.last == '/' end |
#exist? ⇒ Boolean
47 48 49 |
# File 'lib/dutiful/application_file.rb', line 47 def exist? File.exist? full_path end |
#has_backup? ⇒ Boolean
51 52 53 |
# File 'lib/dutiful/application_file.rb', line 51 def has_backup? Dutiful::Config.storage.exist? self end |
#has_condition? ⇒ Boolean
55 56 57 |
# File 'lib/dutiful/application_file.rb', line 55 def has_condition? @command end |
#meets_conditions? ⇒ Boolean
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dutiful/application_file.rb', line 29 def meets_conditions? if has_condition? output = `#{@command}` if @expected_status $?.exitstatus == @expected_status else $?.success? && output.strip == @expected_output end else true end end |
#should_sync? ⇒ Boolean
59 60 61 |
# File 'lib/dutiful/application_file.rb', line 59 def should_sync? (exist? || has_backup?) && meets_conditions? end |
#synced? ⇒ Boolean
63 64 65 |
# File 'lib/dutiful/application_file.rb', line 63 def synced? has_backup? && Dutiful::Config.storage.synced?(self) end |
#timestamp ⇒ Object
25 26 27 |
# File 'lib/dutiful/application_file.rb', line 25 def File.mtime full_path if exist? end |
#to_s ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dutiful/application_file.rb', line 67 def to_s return "#{path} does not meet conditions (skipping)".yellow unless meets_conditions? if exist? if has_backup? if synced? "#{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)".yellow end end |