Class: Devpack::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/devpack/messages.rb

Overview

Generates output messages.

Class Method Summary collapse

Class Method Details

.alert_incompatible(incompatible) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/devpack/messages.rb', line 45

def alert_incompatible(incompatible)
  grouped_dependencies = {}
  incompatible.each do |spec, dependencies|
    key = spec.root.pretty_name
    grouped_dependencies[key] ||= []
    grouped_dependencies[key] << dependencies
  end
  alert_incompatible_message(grouped_dependencies)
end

.color(name) ⇒ Object



65
66
67
# File 'lib/devpack/messages.rb', line 65

def color(name)
  "#{palette.fetch(name)}#{yield}#{palette.fetch(:reset)}"
end

.failure(name, error_message) ⇒ Object



7
8
9
10
# File 'lib/devpack/messages.rb', line 7

def failure(name, error_message)
  base = "Failed to load `#{name}`"
  "#{base}. #{error_message}"
end

.initializer_failure(path, error_message) ⇒ Object



12
13
14
# File 'lib/devpack/messages.rb', line 12

def initializer_failure(path, error_message)
  "Failed to load initializer `#{path}`: #{error_message}"
end

.install_missing(missing) ⇒ Object



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

def install_missing(missing)
  command = color(:cyan) { 'bundle exec devpack install' }
  grouped_missing = missing
                    .group_by(&:root)
                    .map do |root, dependencies|
    next (color(:cyan) { root.pretty_name }).to_s if dependencies.all?(&:root?)

    formatted_dependencies = dependencies.map { |dependency| color(:yellow) { dependency.pretty_name } }
    "#{color(:cyan) { root.pretty_name }}: #{formatted_dependencies.join(', ')}"
  end
  "Install #{missing.size} missing gem(s): #{command} # [#{grouped_missing.join(', ')}]"
end

.loaded(config, gems, time) ⇒ Object

rubocop:disable Metrics/AbcSize



17
18
19
20
21
22
23
24
25
# File 'lib/devpack/messages.rb', line 17

def loaded(config, gems, time)
  loaded = gems.size - gems.reject { |_, devpack_loaded| devpack_loaded }.size
  of_total = gems.size == config.requested_gems.size ? nil : " of #{color(:cyan) { config.requested_gems.size }}"
  path = color(:cyan) { config.devpack_path }
  base = "Loaded #{color(:green) { loaded }}#{of_total} development gem(s) from #{path} in #{time} seconds"
  return "#{base}." if loaded == gems.size

  "#{base} (#{color(:cyan) { gems.size - loaded }} gem(s) were already loaded by environment)."
end

.loaded_initializers(path, initializers, time) ⇒ Object

rubocop:enable Metrics/AbcSize



28
29
30
# File 'lib/devpack/messages.rb', line 28

def loaded_initializers(path, initializers, time)
  "Loaded #{color(:green) { initializers.compact.size }} initializer(s) from '#{path}' in #{time} seconds"
end

.no_gems_to_installObject



55
56
57
58
# File 'lib/devpack/messages.rb', line 55

def no_gems_to_install
  "No gems to install: #{Devpack::Messages.color(:green) { Devpack.config.requested_gems.size.to_s }} "\
    "gems already installed from #{Devpack::Messages.color(:cyan) { Devpack.config.devpack_path }}"
end

.testObject



60
61
62
63
# File 'lib/devpack/messages.rb', line 60

def test
  puts "#{color(:green) { 'green' }} #{color(:red) { 'red' }} #{color(:blue) { 'blue' }}"
  puts "#{color(:cyan) { 'cyan' }} #{color(:yellow) { 'yellow' }} #{color(:magenta) { 'magenta' }}"
end