Class: Msgr::CLI
- Inherits:
-
Object
- Object
- Msgr::CLI
- Defined in:
- lib/msgr/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ CLI
Returns a new instance of CLI.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/msgr/cli.rb', line 9 def initialize() @options = if !File.exist?([:require]) || (File.directory?([:require]) && !File.exist?("#{[:require]}/config/application.rb")) raise <<~ERR Rails application or required ruby file not found: #{[:require]} ERR end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/msgr/cli.rb', line 7 def @options end |
Class Method Details
.run(argv) ⇒ Object
59 60 61 |
# File 'lib/msgr/cli.rb', line 59 def run(argv) new(parse(argv)).run end |
Instance Method Details
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/msgr/cli.rb', line 21 def run ENV['RACK_ENV'] = ENV['RAILS_ENV'] = [:environment] if File.directory?([:require]) require 'rails' if ::Rails::VERSION::MAJOR == 4 require File.("#{[:require]}/config/application.rb") ::Rails::Application.initializer 'msgr.eager_load' do ::Rails.application.config.eager_load = true end end require 'msgr/railtie' require File.("#{[:require]}/config/environment.rb") else require([:require]) end r, w = IO.pipe Signal.trap('INT') { w.puts 'INT' } Signal.trap('TERM') { w.puts 'TERM' } Msgr.logger = Logger.new(STDOUT) Msgr.client.start while (readable = IO.select([r])) case readable.first[0].gets.strip when 'INT', 'TERM' Msgr.client.stop break else exit 1 end end end |