Class: Dutiful::Application
- Inherits:
-
Object
- Object
- Dutiful::Application
- Defined in:
- lib/dutiful/application.rb
Class Method Summary collapse
Instance Method Summary collapse
- #exist? ⇒ Boolean
- #files ⇒ Object
-
#initialize(path) ⇒ Application
constructor
A new instance of Application.
- #name ⇒ Object
- #sync ⇒ Object
- #to_s ⇒ Object
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
37 38 39 40 41 |
# File 'lib/dutiful/application.rb', line 37 def self.all Dir["#{Dutiful.dir}/db/*.toml"].map do |filename| Dutiful::Application.new filename end.compact end |
.each ⇒ Object
43 44 45 46 47 |
# File 'lib/dutiful/application.rb', line 43 def self.each return enum_for(:each) unless block_given? all.each { |application| yield application } end |
Instance Method Details
#exist? ⇒ Boolean
14 15 16 |
# File 'lib/dutiful/application.rb', line 14 def exist? files.any? &:exist? end |
#files ⇒ Object
10 11 12 |
# File 'lib/dutiful/application.rb', line 10 def files content[:files].map { |file| Dutiful::ApplicationFile.new file[:path] } end |
#name ⇒ Object
6 7 8 |
# File 'lib/dutiful/application.rb', line 6 def name content[:application][:name] end |
#sync ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dutiful/application.rb', line 18 def sync files.each do |file| if file.exist? || file.has_backup? result = Dutiful::Config.storage.sync(file) yield file, result if block_given? else yield file if block_given? end end end |
#to_s ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/dutiful/application.rb', line 29 def to_s output = "#{name}:\n" output << files.map do |file| " #{file}" if file.exist? || file.has_backup? end.compact.join("\n") end |