Class: HonestPubsub::CLI
- Inherits:
-
Object
- Object
- HonestPubsub::CLI
- Includes:
- Singleton
- Defined in:
- lib/honest_pubsub/cli.rb
Instance Attribute Summary collapse
-
#pidfile ⇒ Object
Returns the value of attribute pidfile.
-
#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/honest_pubsub/cli.rb', line 13 def pidfile @pidfile end |
#subscribers ⇒ Object
Returns the value of attribute subscribers.
13 14 15 |
# File 'lib/honest_pubsub/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 |
# File 'lib/honest_pubsub/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 '-v', '--version', "Print version and exit" do |arg| puts "HonestPubsub #{HonestPubsub::VERSION}" abort end end optparse.parse!(args) end |
#remove_pid ⇒ Object
60 61 62 63 |
# File 'lib/honest_pubsub/cli.rb', line 60 def remove_pid return unless pidfile File.delete(pidfile) if File.exist?(pidfile) end |
#require_path ⇒ Object
46 47 48 |
# File 'lib/honest_pubsub/cli.rb', line 46 def require_path @require_path || "." end |
#run ⇒ Object
40 41 42 43 44 |
# File 'lib/honest_pubsub/cli.rb', line 40 def run load_environment write_pidfile load_subscribers end |
#subscriber_classes ⇒ Array
Returns array of subscriber classes that will be executed by the CLI
52 53 54 55 56 57 58 |
# File 'lib/honest_pubsub/cli.rb', line 52 def subscriber_classes if subscribers.present? subscribers.map(&:constantize) else HonestPubsub::Subscriber.class_variable_get(:@@registered_subscribers) end end |