Class: Fanfeedrb::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/fanfeedrb/runner.rb

Defined Under Namespace

Classes: Base

Constant Summary collapse

COLORS =
{
  :black   => 0,
  :red     => 1,
  :green   => 2,
  :yellow  => 3,
  :blue    => 4,
  :magenta => 5,
  :cyan    => 6,
  :white   => 7
}
STATE_COLORS =
{
  nil           => COLORS[:black],
  "rejected"    => COLORS[:red],
  "accepted"    => COLORS[:green],
  "delivered"   => COLORS[:yellow],
  "unscheduled" => COLORS[:white],
  "started"     => COLORS[:magenta],
  "finished"    => COLORS[:cyan],
  "unstarted"   => COLORS[:blue]
}
STATE_SYMBOLS =
{
  "unscheduled" => "  ",
  "unstarted"   => ":|",
  "started"     => ":/",
  "finished"    => ":)",
  "delivered"   => ";)",
  "rejected"    => ":(",
  "accepted"    => ":D"
}
TYPE_COLORS =
{
  'chore'   => COLORS[:blue],
  'feature' => COLORS[:magenta],
  'bug'     => COLORS[:red],
  'release' => COLORS[:cyan]
}
TYPE_SYMBOLS =
{
  "feature" => "*",
  "chore"   => "%",
  "release" => "!",
  "bug"     => "/"
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



450
451
452
# File 'lib/fanfeedrb/runner.rb', line 450

def initialize(argv)
  @argv = argv
end

Class Method Details

.[](command) ⇒ Object



188
189
190
191
192
193
194
195
196
# File 'lib/fanfeedrb/runner.rb', line 188

def self.[](command)
  klass_name = command.to_s.capitalize.gsub(/[-_](.)/) { $1.upcase }
  if klass_name =~ /^[A-Z]\w*$/ && const_defined?(klass_name)
    klass = const_get(klass_name)
    if Class === klass && klass < Base
      return klass
    end
  end
end

.command(name, &block) ⇒ Object



202
203
204
# File 'lib/fanfeedrb/runner.rb', line 202

def self.command(name, &block)
  const_set(name.to_s.capitalize.gsub(/[-_](.)/) { $1.upcase },Class.new(Base,&block))
end

.commandsObject



198
199
200
# File 'lib/fanfeedrb/runner.rb', line 198

def self.commands
  constants.map {|c| Runner.const_get(c)}.select {|c| Class === c && c < Runner::Base}.sort_by {|r| r.command_name}.uniq
end

Instance Method Details

#runObject



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/fanfeedrb/runner.rb', line 500

def run
  command = @argv.shift
  if klass = self.class[command]
    result = klass.new(@argv).run
    exit result.respond_to?(:to_int) ? result.to_int : 0
  elsif ['help', '--help', '-h', '', nil].include?(command)
    puts "usage: fanfeedrb <command> [options] [arguments]"
    puts
    puts "Commands:"
    self.class.commands.each do |command|
      puts "    %-19s %s" % [command.command_name, command.summary]
    end
    puts
    puts "Run fanfeedrb <command> --help for help with a given command"
  else
    raise Error, "Unknown fanfeedrb command #{command}"
  end
rescue fanfeedrb::Error
  $stderr.puts "#$!"
  exit 1
rescue Interrupt
  $stderr.puts "Interrupted!"
  exit 130
end