Class: Guard::Knife
Constant Summary collapse
- VERSION =
'0.1.2'
Instance Method Summary collapse
-
#initialize(watchers = [], options = {}) ⇒ Knife
constructor
Initialize a Guard.
- #knife_options ⇒ Object
- #normalize(paths) ⇒ Object
-
#reload ⇒ Object
Called when ‘reload|r|z + enter` is pressed.
-
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
-
#run_on_change(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
-
#run_on_deletion(paths) ⇒ Object
Called on file(s) deletions that the Guard watches.
-
#start ⇒ Object
Call once when Guard starts.
-
#stop ⇒ Object
Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
- #upload(path) ⇒ Object
- #upload_cookbook(cookbook) ⇒ Object
- #upload_databag(data_bag, path) ⇒ Object
- #upload_environment(environment) ⇒ Object
- #upload_role(role) ⇒ Object
Constructor Details
#initialize(watchers = [], options = {}) ⇒ Knife
Initialize a Guard.
11 12 13 14 |
# File 'lib/guard/knife.rb', line 11 def initialize(watchers = [], = {}) super @options = {}.update() end |
Instance Method Details
#knife_options ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/guard/knife.rb', line 77 def = '' @options.each do |key, value| case key when :config += "-c #{value} " end end end |
#normalize(paths) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/guard/knife.rb', line 54 def normalize(paths) paths.map! do |path| next if path.match(/\.swp$/) # vim swap file # only upload cookbook once in case many files change path.gsub(/^(cookbooks\/[^\/]*)\/.*$/, '\1') end paths.compact.uniq 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/…
29 30 |
# File 'lib/guard/knife.rb', line 29 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/…
35 36 |
# File 'lib/guard/knife.rb', line 35 def run_all end |
#run_on_change(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
41 42 43 44 45 46 |
# File 'lib/guard/knife.rb', line 41 def run_on_change(paths) paths = normalize(paths) paths.each do |path| upload(path) end end |
#run_on_deletion(paths) ⇒ Object
Called on file(s) deletions that the Guard watches.
51 52 |
# File 'lib/guard/knife.rb', line 51 def run_on_deletion(paths) end |
#start ⇒ Object
Call once when Guard starts. Please override initialize method to init stuff.
18 19 |
# File 'lib/guard/knife.rb', line 18 def start end |
#stop ⇒ Object
Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
23 24 |
# File 'lib/guard/knife.rb', line 23 def stop end |
#upload(path) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/guard/knife.rb', line 64 def upload(path) if path.match(/^cookbooks\/([^\/]*)/) upload_cookbook($1) elsif path.match(/^data_bags\/(.*)\/.*\.json$/) data_bag = $1 upload_databag(data_bag, path) elsif path.match(/^(environments\/.*\.rb)$/) upload_environment($1) elsif path.match(/^(roles\/.*.rb)$/) upload_role($1) end end |
#upload_cookbook(cookbook) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/guard/knife.rb', line 89 def upload_cookbook(cookbook) if system("knife cookbook upload #{cookbook} #{}") ::Guard::Notifier.notify("Cookbook #{cookbook} uploaded", :title => 'Knife') else ::Guard::Notifier.notify("Cookbook #{cookbook} failed to upload", :title => 'Knife', :image => :failed) end end |
#upload_databag(data_bag, path) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/guard/knife.rb', line 97 def upload_databag(data_bag, path) item = File.basename path, '.json' if system("knife data bag from file #{data_bag} #{path} #{}") ::Guard::Notifier.notify("Data bag item #{data_bag}::#{item} uploaded", :title => 'Knife') else ::Guard::Notifier.notify("Data bag item #{data_bag}::#{item} failed to upload", :title => 'Knife', :image => :failed) end end |
#upload_environment(environment) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/guard/knife.rb', line 106 def upload_environment(environment) if system("knife environment from file #{environment} #{}") ::Guard::Notifier.notify("Environment #{environment} uploaded", :title => 'Knife') else ::Guard::Notifier.notify("Environment #{environment} failed to upload", :title => 'Knife', :image => :failed) end end |
#upload_role(role) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/guard/knife.rb', line 114 def upload_role(role) if system("knife role from file #{role} #{}") ::Guard::Notifier.notify("Role #{role} uploaded", :title => 'Knife') else ::Guard::Notifier.notify("Role #{role} upload failed", :title => 'Knife', :image => :failed) end end |