Class: Banter::CLI

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/banter/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pidfileObject

Returns the value of attribute pidfile.



13
14
15
# File 'lib/banter/cli.rb', line 13

def pidfile
  @pidfile
end

#process_nameObject

Returns the value of attribute process_name.



13
14
15
# File 'lib/banter/cli.rb', line 13

def process_name
  @process_name
end

#subscribersObject

Returns the value of attribute subscribers.



13
14
15
# File 'lib/banter/cli.rb', line 13

def subscribers
  @subscribers
end

Instance Method Details

#parse(args = ARGV) ⇒ Object

Method to support parsing of arguments passed through the command line



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/banter/cli.rb', line 16

def parse(args = ARGV)
  optparse = OptionParser.new do |opts|
    opts.banner = "Usage: bundle exec start_subscribers [options]"
    opts.on '-P', '--pidfile PATH', "path to pidfile" do |arg|
      @pidfile = arg
    end

    opts.on("-o", "--only [SUBSCRIBERS]", "comma separated name of subsriber classes that should be run") do |subscribers|
      @subscribers = subscribers.split(/\,/)
    end

    opts.on '-r', '--require [PATH|DIR]', "Location of Rails application with workers or file to require" do |arg|
      @require_path = arg
    end

    opts.on '-n', '--name [PROCESS_NAME]', "Name of the process" do |arg|
      @process_name = arg
    end

    opts.on '-v', '--version', "Print version and exit" do
      puts "Banter #{Banter::VERSION}"
      abort
    end
  end

  optparse.parse!(args)
end

#remove_pidObject



65
66
67
68
# File 'lib/banter/cli.rb', line 65

def remove_pid
  return unless pidfile
  File.delete(pidfile) if File.exist?(pidfile)
end

#require_pathObject



51
52
53
# File 'lib/banter/cli.rb', line 51

def require_path
  @require_path || "."
end

#runObject



44
45
46
47
48
49
# File 'lib/banter/cli.rb', line 44

def run
  change_process_name
  load_environment
  write_pidfile
  load_subscribers
end

#subscriber_classesArray

Returns array of subscriber classes that will be executed by the CLI

Returns:

  • (Array)

    returns array of subscriber classes that will be executed by the CLI



57
58
59
60
61
62
63
# File 'lib/banter/cli.rb', line 57

def subscriber_classes
  if subscribers.present?
    subscribers.map(&:constantize)
  else
    Banter::Subscriber.class_variable_get(:@@registered_subscribers)
  end
end