Class: Guard::Puma
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Puma
- Defined in:
- lib/guard/puma.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :pumactl => false, :port => 4000, :environment => default_env, :start_on_start => true, :force_run => false, :timeout => 20, :restart_timeout => 1, :debugger => false, :notifications => %i[restarting restarted not_restarted stopped] }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Puma
constructor
A new instance of Puma.
- #reload ⇒ Object
- #run_on_changes(paths) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Puma
Returns a new instance of Puma.
25 26 27 28 29 30 31 |
# File 'lib/guard/puma.rb', line 25 def initialize( = {}) super @options = DEFAULT_OPTIONS.merge() @options[:port] = nil if @options.key?(:config) @runner = ::Guard::PumaRunner.new(@options) @last_restarted = Time.now end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/guard/puma.rb', line 7 def @options end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
7 8 9 |
# File 'lib/guard/puma.rb', line 7 def runner @runner end |
Class Method Details
.default_env ⇒ Object
9 10 11 |
# File 'lib/guard/puma.rb', line 9 def self.default_env ENV.fetch('RACK_ENV', 'development') end |
Instance Method Details
#reload ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/guard/puma.rb', line 42 def reload return if (Time.now - @last_restarted) < [:restart_timeout] @last_restarted = Time.now Compat::UI.info "Restarting Puma..." if [:notifications].include?(:restarting) Compat::UI.notify( "Puma restarting#{port_text} in #{[:environment]} environment...", title: "Restarting Puma...", image: :pending ) end if runner.restart Compat::UI.info "Puma restarted" if [:notifications].include?(:restarted) Compat::UI.notify( "Puma restarted#{port_text}.", title: "Puma restarted!", image: :success ) end else Compat::UI.info "Puma NOT restarted, check your log files." if [:notifications].include?(:not_restarted) Compat::UI.notify( "Puma NOT restarted, check your log files.", title: "Puma NOT restarted!", image: :failed ) end end end |
#run_on_changes(paths) ⇒ Object
82 83 84 |
# File 'lib/guard/puma.rb', line 82 def run_on_changes(paths) reload end |
#start ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/guard/puma.rb', line 33 def start return unless [:start_on_start] server = [:server] ? "#{[:server]} and " : "" Compat::UI.info( "Puma starting#{port_text} in #{server}#{[:environment]} environment." ) runner.start end |
#stop ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/guard/puma.rb', line 71 def stop return unless [:start_on_start] if [:notifications].include?(:stopped) Compat::UI.notify( "Until next time...", title: "Puma shutting down.", image: :pending ) end runner.halt end |