Class: Banter::CLI
Instance Attribute Summary collapse
-
#pidfile ⇒ Object
Returns the value of attribute pidfile.
-
#process_name ⇒ Object
Returns the value of attribute process_name.
-
#subscribers ⇒ Object
Returns the value of attribute subscribers.
Instance Method Summary collapse
-
#parse(args = ARGV) ⇒ Object
Method to support parsing of arguments passed through the command line.
- #remove_pid ⇒ Object
- #require_path ⇒ Object
- #run ⇒ Object
-
#subscriber_classes ⇒ Array
Returns array of subscriber classes that will be executed by the CLI.
Instance Attribute Details
#pidfile ⇒ Object
Returns the value of attribute pidfile.
13 14 15 |
# File 'lib/banter/cli.rb', line 13 def pidfile @pidfile end |
#process_name ⇒ Object
Returns the value of attribute process_name.
13 14 15 |
# File 'lib/banter/cli.rb', line 13 def process_name @process_name end |
#subscribers ⇒ Object
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. = "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_pid ⇒ Object
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_path ⇒ Object
51 52 53 |
# File 'lib/banter/cli.rb', line 51 def require_path @require_path || "." end |
#run ⇒ Object
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_classes ⇒ 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 |