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
- #defaults ⇒ Object
- #exist? ⇒ Boolean
- #files ⇒ Object
- #has_backup? ⇒ Boolean
-
#initialize(path) ⇒ Application
constructor
A new instance of Application.
- #name ⇒ Object
- #restore(&block) ⇒ Object
- #tracked? ⇒ 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
52 53 54 55 56 |
# 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 ⇒ Object
58 59 60 61 62 |
# File 'lib/dutiful/application.rb', line 58 def self.each return enum_for(:each) unless block_given? all.each { |application| yield application } end |
Instance Method Details
#backup(&block) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# 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 ⇒ Object
6 7 8 9 10 |
# 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? ⇒ Boolean
40 41 42 |
# File 'lib/dutiful/application.rb', line 40 def exist? files.any?(&:exist?) || defaults.any?(&:exist?) end |
#files ⇒ Object
12 13 14 |
# File 'lib/dutiful/application.rb', line 12 def files Array(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?) || defaults.any?(&:has_backup?) end |
#name ⇒ Object
16 17 18 |
# File 'lib/dutiful/application.rb', line 16 def name content[:application][:name] end |
#restore(&block) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# 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? ⇒ Boolean
48 49 50 |
# File 'lib/dutiful/application.rb', line 48 def tracked? exist? || has_backup? end |