class BBC::Cosmos::Tools::Commands::Base

Attributes

config[RW]

Public Class Methods

new(args = [], local_options = {}, config = {}) click to toggle source
Calls superclass method
# File lib/bbc/cosmos/tools/commands/base.rb, line 22
def initialize(args = [], local_options = {}, config = {})
  super(args, local_options, config)
  setup_config
end

Protected Instance Methods

api_error(response, die = true) click to toggle source
# File lib/bbc/cosmos/tools/commands/base.rb, line 44
def api_error(response, die = true)
  error_message = JSON.parse(response.body)["message"]
  error(error_message, die)
end
banner(component = nil) click to toggle source
build_table(headers, data) click to toggle source
# File lib/bbc/cosmos/tools/commands/base.rb, line 49
def build_table(headers, data)
  [].tap do |table|
    table << headers.reduce([]) do |array, header|
      array << set_color(header, :cyan)
    end

    data.each do |items|
      table << items.map { |item| set_color(item, :white) }
    end
  end
end
components(options, component = nil) click to toggle source
# File lib/bbc/cosmos/tools/commands/base.rb, line 40
def components(options, component = nil)
  components = component.nil? ? config.components_for(options[:tags]).keys : [component]
end
error(message, die = true) click to toggle source
# File lib/bbc/cosmos/tools/commands/base.rb, line 61
def error(message, die = true)
  say "#{message}\n", :red
  exit 1 if die
end
get_key_value(key, value) click to toggle source
# File lib/bbc/cosmos/tools/commands/base.rb, line 29
def get_key_value(key, value)
  "#{set_color("#{key}:", :cyan)} #{set_color(value, :white)}"
end

Private Instance Methods

setup_config() click to toggle source
# File lib/bbc/cosmos/tools/commands/base.rb, line 68
def setup_config
  config_base = !options[:base].nil? && File.directory?(options[:base]) ? Pathname.new(options[:base]) : Pathname.pwd.join(".")
  fail("Config directory: #{config_base} doesn't exist") unless File.directory?(config_base)
  @config = BBC::Cosmos::Tools::Config.new(
    config_base,
    options[:project],
    options[:env]
  )
end