Class: Rpush::CLI
- Inherits:
-
Thor
- Object
- Thor
- Rpush::CLI
- Defined in:
- lib/rpush/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.default_config_path ⇒ Object
12 13 14 |
# File 'lib/rpush/cli.rb', line 12 def self.default_config_path detect_rails? ? 'config/initializers/rpush.rb' : 'config/rpush.rb' end |
.detect_rails? ⇒ Boolean
8 9 10 |
# File 'lib/rpush/cli.rb', line 8 def self.detect_rails? ['bin/rails', 'script/rails'].any? { |path| File.exist?(path) } end |
Instance Method Details
#init ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rpush/cli.rb', line 54 def init underscore_option_names require 'rails/generators' puts "* " + Rainbow('Installing config...').green $RPUSH_CONFIG_PATH = default_config_path # rubocop:disable Style/GlobalVars Rails::Generators.invoke('rpush_config') install_migrations = ['active_record'] unless .key?('active_record') answer = ask("\n* #{Rainbow('Install ActiveRecord migrations?').green}", limited_to: %w[y n]) install_migrations = answer == 'y' end Rails::Generators.invoke('rpush_migration', ['--force']) if install_migrations puts "\n* #{Rainbow('Next steps:').green}" puts " - Run 'bundle exec rake db:migrate'." if install_migrations puts " - Review and update your configuration in #{default_config_path}." puts " - Create your first app, see https://github.com/rpush/rpush for examples." puts " - Run 'rpush help' for commands and options." end |
#push ⇒ Object
79 80 81 82 83 84 |
# File 'lib/rpush/cli.rb', line 79 def push config_setup Rpush.config.foreground = true Rpush.push end |
#start ⇒ Object
22 23 24 25 26 27 |
# File 'lib/rpush/cli.rb', line 22 def start config_setup require 'rpush/daemon' Rpush::Daemon.start end |
#status ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/rpush/cli.rb', line 87 def status config_setup require 'rpush/daemon' rpc = Rpush::Daemon::Rpc::Client.new(rpush_process_pid) status = rpc.status rpc.close puts humanize_json(status) end |
#stop ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rpush/cli.rb', line 31 def stop config_setup pid = rpush_process_pid return unless pid STDOUT.write "* Stopping Rpush (pid #{pid})... " STDOUT.flush Process.kill('TERM', pid) loop do begin Process.getpgid(pid) sleep 0.05 rescue Errno::ESRCH break end end puts Rainbow('✔').green end |