Class: Dutiful::Application
- Inherits:
-
Object
- Object
- Dutiful::Application
- Defined in:
- lib/dutiful/application.rb
Class Method Summary collapse
Instance Method Summary collapse
- #backup(&block) ⇒ Object
- #exist? ⇒ Boolean
- #files ⇒ Object
- #has_backup? ⇒ Boolean
-
#initialize(path) ⇒ Application
constructor
A new instance of Application.
- #name ⇒ Object
- #restore(&block) ⇒ Object
- #should_sync? ⇒ Boolean
- #sync(backup_only: false, restore_only: false) ⇒ Object
- #synced? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ Application
Returns a new instance of Application.
2 3 4 |
# File 'lib/dutiful/application.rb', line 2 def initialize(path) @path = path end |
Class Method Details
.all ⇒ Object
56 57 58 59 60 |
# File 'lib/dutiful/application.rb', line 56 def self.all Dir["#{Dutiful.dir}/db/*.toml"].map do |filename| Dutiful::Application.new filename end.compact end |
.each ⇒ Object
62 63 64 65 66 |
# File 'lib/dutiful/application.rb', line 62 def self.each return enum_for(:each) unless block_given? all.each { |application| yield application } end |
Instance Method Details
#backup(&block) ⇒ Object
14 15 16 |
# File 'lib/dutiful/application.rb', line 14 def backup(&block) sync backup_only: true, &block end |
#exist? ⇒ Boolean
40 41 42 |
# File 'lib/dutiful/application.rb', line 40 def exist? files.any? &:exist? end |
#files ⇒ Object
6 7 8 |
# File 'lib/dutiful/application.rb', line 6 def files content[:file].map { |file| Dutiful::ApplicationFile.new file[:path], file[:condition] } end |
#has_backup? ⇒ Boolean
44 45 46 |
# File 'lib/dutiful/application.rb', line 44 def has_backup? files.any? &:has_backup? end |
#name ⇒ Object
10 11 12 |
# File 'lib/dutiful/application.rb', line 10 def name content[:application][:name] end |
#restore(&block) ⇒ Object
18 19 20 |
# File 'lib/dutiful/application.rb', line 18 def restore(&block) sync restore_only: true, &block end |
#should_sync? ⇒ Boolean
48 49 50 |
# File 'lib/dutiful/application.rb', line 48 def should_sync? exist? || has_backup? end |
#sync(backup_only: false, restore_only: false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dutiful/application.rb', line 22 def sync(backup_only: false, restore_only: false) files.each do |file| if file.should_sync? result = if backup_only && file.exist? Dutiful::Config.storage.backup(file) elsif restore_only && file.has_backup? Dutiful::Config.storage.restore(file) else Dutiful::Config.storage.sync(file) end yield file, result if block_given? else yield file if block_given? end end end |
#synced? ⇒ Boolean
52 53 54 |
# File 'lib/dutiful/application.rb', line 52 def synced? files.all? &:synced? end |