Class: Dutiful::Application

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

Class Method Summary collapse

Instance Method Summary collapse

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

.allObject



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

.eachObject



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

Returns:

  • (Boolean)


14
15
16
# File 'lib/dutiful/application.rb', line 14

def exist?
  files.any? &:exist?
end

#filesObject



10
11
12
# File 'lib/dutiful/application.rb', line 10

def files
  content[:files].map { |file| Dutiful::ApplicationFile.new file[:path] }
end

#nameObject



6
7
8
# File 'lib/dutiful/application.rb', line 6

def name
  content[:application][:name]
end

#syncObject



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_sObject



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