class Startling::Commands::Base

Attributes

cli_options[R]
logger[R]

Public Class Methods

new(attrs={}) click to toggle source
# File lib/startling/commands/base.rb, line 12
def initialize(attrs={})
  @cli_options = attrs
  attrs.each do |attr, value|
    self.class.__send__(:attr_reader, attr)
    instance_variable_set("@#{attr}", value)
  end

  @logger = Logger.new(STDOUT)
  @logger.formatter = -> (severity, datetime, progname, msg) { "#{msg}\n" }
  @logger.level = (attrs[:verbose]) ? Logger::DEBUG : Logger::INFO
end
run(attrs={}) click to toggle source
# File lib/startling/commands/base.rb, line 8
def self.run(attrs={})
  new(attrs).execute
end

Public Instance Methods

command_class(command) click to toggle source
# File lib/startling/commands/base.rb, line 60
def command_class(command)
  begin
    Startling::Commands.const_get(to_camel_case(command.to_s))
  rescue NameError
    print_name_error_message(command, Startling::Configuration::DEFAULT_COMMAND_PATH)
    exit
  end
end
execute() click to toggle source
# File lib/startling/commands/base.rb, line 24
def execute
  raise NotImplementedError
end
handler_class(handler) click to toggle source
# File lib/startling/commands/base.rb, line 51
def handler_class(handler)
  begin
    Startling::Handlers.const_get(to_camel_case(handler.to_s))
  rescue NameError
    print_name_error_message(handler, Startling::Configuration::DEFAULT_HANDLER_PATH)
    exit
  end
end
load_commands() click to toggle source
# File lib/startling/commands/base.rb, line 37
def load_commands
  loaded_commands_path = Startling::Configuration.load_commands
  if loaded_commands_path
    logger.debug "Loading commands #{loaded_commands_path}"
  end
end
load_configuration() click to toggle source
# File lib/startling/commands/base.rb, line 28
def load_configuration
  loaded_configuration_path = Startling::Configuration.load_configuration
  if loaded_configuration_path
    logger.debug "Loading configuration #{loaded_configuration_path}"
  else
    logger.debug "Using default configuration"
  end
end
load_handlers() click to toggle source
# File lib/startling/commands/base.rb, line 44
def load_handlers
  loaded_handlers_path = Startling::Configuration.load_handlers
  if loaded_handlers_path
    logger.debug "Loading handlers #{loaded_handlers_path}"
  end
end
print_args(context) click to toggle source
print_name_error_message(name, path) click to toggle source
to_camel_case(lower_case_and_underscored_word, first_letter_in_uppercase = true) click to toggle source
# File lib/startling/commands/base.rb, line 80
def to_camel_case(lower_case_and_underscored_word, first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
  else
    lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
  end
end