Module: Drakkon::Gems::Bundle

Defined in:
lib/drakkon/gem/bundle.rb

Overview

Run Command for CLI

Class Method Summary collapse

Class Method Details

.build!(args, context) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/drakkon/gem/bundle.rb', line 5

def self.build!(args, context)
  return if Settings.gems.empty?

  @context = context

  if Settings.config[:bundle_digest] == digest && !args.include?('bundle')
    LogBot.info('Gems Bundle', 'Nothing New')
    return unless args.include?('bundle')
  else
    LogBot.info('Gems Bundle', 'Bundling')
  end

  idx = collect

  do_the_bundle(idx)

  Settings.update(:bundle_digest, digest)
rescue TTY::Reader::InputInterrupt
  exit 0
end

.bundle_fileObject

General Helpers



100
101
102
# File 'lib/drakkon/gem/bundle.rb', line 100

def self.bundle_file
  "#{drakkon_dir}/bundle.rb"
end

.collectObject



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

def self.collect
  idx = {}
  Settings.gems.each_value do |gem|
    case gem[:source].to_sym
    when :local then collect_local_source(idx, gem)
    else
      LogBot.fatal('Bundle', "Invalid Source: #{gem[:source].pastel(:red)}")
    end
  end

  idx
end

.collect_local_source(idx, gem) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/drakkon/gem/bundle.rb', line 67

def self.collect_local_source(idx, gem)
  path = gem[:data][:path]

  # Modules
  gem[:data][:modules].each do |mod|
    idx[mod.weight] ||= []
    mod.files.each do |file|
      file_name = "#{path}/#{file}.rb"
      unless File.exist?(file_name)
        LogBot.fatal('Bundle',
                     "Module File not found #{mod.name.pastel(:bright_blue)}, #{file_name.pastel(:red)}")
        next
      end

      idx[mod.weight].push file_name
    end
  end

  # Files
  if gem[:data].key?(:files)
    gem[:data][:files].each_value do |f|
      idx[f.weight] ||= []
      idx[f.weight].push "#{path}/#{f.file}"
    end

  end

  # Return
end

.digestObject



112
113
114
# File 'lib/drakkon/gem/bundle.rb', line 112

def self.digest
  Digest::MD5.hexdigest Settings.gems.to_s
end

.do_the_bundle(idx) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/drakkon/gem/bundle.rb', line 26

def self.do_the_bundle(idx)
  # Make Directory `app/drakkon` if it doesn't exist
  FileUtils.mkdir_p('app/drakkon') unless File.directory?('app/drakkon')

  # Touch the file if it doesn't exist
  FileUtils.touch(bundle_file) unless File.exist?(bundle_file)

  File.open(bundle_file, 'w') do |f|
    # Index Writer
    idx.keys.sort.reverse.each do |i|
      idx[i].each do |file|
        unless File.exist?(file)
          LogBot.fatal('Bundle', "File not found #{file.pastel(:red)}")
          next
        end
        f << File.read(file)
        f << "\n"
      end
    end

    # Include other files
    f << "require 'app/drakkon/image_index.rb' \n" if Settings.image_index?
    f << "require 'app/drakkon/manifest.rb' \n" if Settings.manifest?

    # File Close
  end
end

.drakkon_dirObject



104
105
106
# File 'lib/drakkon/gem/bundle.rb', line 104

def self.drakkon_dir
  "#{@context}/app/drakkon"
end

.promptObject



108
109
110
# File 'lib/drakkon/gem/bundle.rb', line 108

def self.prompt
  TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
end