Module: Drakkon::Manifest

Defined in:
lib/drakkon/lib/manifest.rb

Overview

Helper to Generate Manifest

Class Method Summary collapse

Class Method Details

.digestObject



45
46
47
# File 'lib/drakkon/lib/manifest.rb', line 45

def self.digest
  Digest::MD5.hexdigest(list.map { |x| Digest::MD5.file(x).hexdigest }.join)
end

.indexObject

Split out | Just collect information



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/drakkon/lib/manifest.rb', line 33

def self.index
  list
  search("#{Dir.pwd}/app")

  # General Cleanup
  list.reject! { |x| x.include? 'app/main.rb' }

  list.map! do |file|
    file.gsub(root_directory, '')
  end
end

.listObject



49
50
51
52
53
# File 'lib/drakkon/lib/manifest.rb', line 49

def self.list
  @list ||= []

  @list
end

.requiredObject

Generate Require Statements Sure there gonna be plenty of opinions on this bad boi



70
71
72
73
74
75
76
77
# File 'lib/drakkon/lib/manifest.rb', line 70

def self.required
  require_strings = ''
  list.reverse.each do |file|
    require_strings << "require '#{file}'\n"
  end

  require_strings
end

.root_directoryObject



11
12
13
# File 'lib/drakkon/lib/manifest.rb', line 11

def self.root_directory
  "#{Dir.pwd}/"
end

.run!(force: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/drakkon/lib/manifest.rb', line 15

def self.run!(force: false)
  index

  if Settings.config[:manifest_digest] == digest && File.exist?('app/drakkon/manifest.rb')
    LogBot.info('Manifest', 'Nothing New')
    return unless force
  end

  Settings.update(:manifest_digest, digest)

  LogBot.info('Manifest', 'Saved!')

  # Make Directory `app/drakkon` if it doesn't exist
  FileUtils.mkdir_p('app/drakkon') unless File.directory?('app/drakkon')
  File.write('app/drakkon/manifest.rb', required)
end

.search(dir) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/drakkon/lib/manifest.rb', line 55

def self.search(dir)
  # Skip Drakkon
  return if dir.include?('app/drakkon')

  @list.concat Dir["#{dir}/*.rb"]

  Dir["#{dir}/*"].each do |file|
    next unless File.directory?(file)

    Manifest.search(file)
  end
end