class Rascal::CLI::Base

Public Class Methods

new(thor, options) click to toggle source
# File lib/rascal/cli/base.rb, line 6
def initialize(thor, options)
  @thor = thor
  @options = options
end

Private Instance Methods

config_location() click to toggle source
# File lib/rascal/cli/base.rb, line 13
def config_location
  Pathname.new(@options[:config_file]).expand_path
end
each_environment(name) { |environment| ... } click to toggle source
# File lib/rascal/cli/base.rb, line 35
def each_environment(name, &block)
  return enum_for(:each_environment) unless block_given?

  if name == :all
    definition = environment_definition
    definition.available_environment_names.each do |environment_name|
      yield definition.environment(environment_name)
    end
  else
    yield find_environment(name)
  end
end
environment_definition() click to toggle source
# File lib/rascal/cli/base.rb, line 48
def environment_definition
  if (definition = EnvironmentsDefinition.detect(config_location))
    definition
  else
    fail_with_error("Could not find an environment definition in current working directory.")
    nil
  end
end
fail_with_error(message) click to toggle source
# File lib/rascal/cli/base.rb, line 17
def fail_with_error(message)
  raise Thor::Error, message
end
find_environment(environment_name) click to toggle source
# File lib/rascal/cli/base.rb, line 21
def find_environment(environment_name)
  definition = environment_definition
  if (environment = definition.environment(environment_name))
    return environment
  else
    available_environments = definition.available_environment_names.join(', ')
    if environment_name
      fail_with_error("Unknown environment #{environment_name}. Available: #{available_environments}.")
    else
      fail_with_error("Missing environment. Available: #{available_environments}.")
    end
  end
end