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.



3
4
5
# File 'lib/dutiful/application.rb', line 3

def initialize(path)
  @path = path
end

Class Method Details

.allObject



48
49
50
51
52
53
54
55
# File 'lib/dutiful/application.rb', line 48

def self.all
  Dir.foreach('db').map do |filename|
    next if filename == '.' or filename == '..'

    application = Dutiful::Application.new "db/#{filename}"
    application if application.exist?
  end.compact
end

.eachObject



57
58
59
60
61
# File 'lib/dutiful/application.rb', line 57

def self.each
  return enum_for(:each) unless block_given?

  all.each { |application| yield application }
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


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

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

#filesObject



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

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

#nameObject



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

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

#syncObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/dutiful/application.rb', line 19

def sync
  files.each do |file|
    if file.exist?
      result = Dutiful::Config.storage.sync(file) if file.exist?
      yield file, result
    else
      yield file
    end
  end
end

#to_sObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dutiful/application.rb', line 30

def to_s
  output = "#{name}:\n"

  files.each_with_index do |file, index|
    next unless file.exist?

    if file.synced?
      output << "  #{file.path} ✔".green
    else
      output << "  #{file.path} (pending)".yellow
    end

    output << "\n" if index < files.count
  end

  output
end