Class: Guard::Docker
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Docker
- Defined in:
- lib/guard/docker.rb
Instance Method Summary collapse
- #failed(message) ⇒ Object
-
#initialize(options = {}) ⇒ Docker
constructor
Initializes a Guard plugin.
- #notify(message, options = {}) ⇒ Object
- #pending(message) ⇒ Object
-
#reload ⇒ Object
Called when ‘reload|r|z + enter` is pressed.
-
#run_all ⇒ Object
Called when just
enteris pressed This method should be principally used for long action like running all specs/tests/… -
#run_on_additions(paths) ⇒ Object
Called on file(s) additions that the Guard plugin watches.
-
#run_on_modifications(paths) ⇒ Object
Called on file(s) modifications that the Guard plugin watches.
-
#run_on_removals(paths) ⇒ Object
Called on file(s) removals that the Guard plugin watches.
-
#start ⇒ Object
Called once when Guard starts.
-
#stop ⇒ Object
Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
- #success(message) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Docker
Initializes a Guard plugin. Don’t do any work here, especially as Guard plugins get initialized even if they are not in an active group!
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/guard/docker.rb', line 14 def initialize( = {}) @image = .fetch(:image, nil) @tag = .fetch(:tag, nil) @host_port = .fetch(:host_port, nil) @container_port = .fetch(:container_port, nil) @env_vars = .fetch(:env_vars, nil) super end |
Instance Method Details
#failed(message) ⇒ Object
123 124 125 |
# File 'lib/guard/docker.rb', line 123 def failed notify , :image => :failed end |
#notify(message, options = {}) ⇒ Object
127 128 129 |
# File 'lib/guard/docker.rb', line 127 def notify(, = {}) Notifier.notify(, ) end |
#pending(message) ⇒ Object
115 116 117 |
# File 'lib/guard/docker.rb', line 115 def pending notify , :image => :pending end |
#reload ⇒ Object
Called when ‘reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…
76 77 |
# File 'lib/guard/docker.rb', line 76 def reload end |
#run_all ⇒ Object
Called when just enter is pressed This method should be principally used for long action like running all specs/tests/…
85 86 |
# File 'lib/guard/docker.rb', line 85 def run_all end |
#run_on_additions(paths) ⇒ Object
Called on file(s) additions that the Guard plugin watches.
94 95 |
# File 'lib/guard/docker.rb', line 94 def run_on_additions(paths) end |
#run_on_modifications(paths) ⇒ Object
Called on file(s) modifications that the Guard plugin watches.
103 104 |
# File 'lib/guard/docker.rb', line 103 def run_on_modifications(paths) end |
#run_on_removals(paths) ⇒ Object
Called on file(s) removals that the Guard plugin watches.
112 113 |
# File 'lib/guard/docker.rb', line 112 def run_on_removals(paths) end |
#start ⇒ Object
Called once when Guard starts. Please override initialize method to init stuff.
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 |
# File 'lib/guard/docker.rb', line 30 def start failed 'You must specify an image' unless @image return false unless @image stop cmd = [] cmd << 'docker run --rm' cmd << "-p #{@host_port}:#{@container_port}" if @host_port && @container_port @env_vars.each do |key, value| cmd << "-e #{key}=#{value}" end if @env_vars if @tag cmd << "--name=guard-#{@image}-#{@tag}" cmd << "#{@image}:#{@tag}" else cmd << "--name=guard-#{@image}" cmd << @image end spawn(cmd.join(' ')) success "#{@image} is running" end |
#stop ⇒ Object
Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
62 63 64 65 66 67 68 |
# File 'lib/guard/docker.rb', line 62 def stop cmd = [] cmd << 'docker stop' cmd << "guard-#{@image}" if !@tag cmd << "guard-#{@image}-#{@tag}" if @tag system(cmd.join(' ')) end |
#success(message) ⇒ Object
119 120 121 |
# File 'lib/guard/docker.rb', line 119 def success notify , :image => :success end |