Class: Guard::CoffeeDripper
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #change_bean(bean) ⇒ Object
- #drip(coffee_script) ⇒ Object
- #drip_all ⇒ Object
-
#initialize(watchers = [], options = {}) ⇒ CoffeeDripper
constructor
A new instance of CoffeeDripper.
- #load_bean(bean) ⇒ Object
- #load_coffee(coffee) ⇒ Object
- #load_config ⇒ Object
-
#reload ⇒ Object
Called on Ctrl-Z signal This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
-
#run_all ⇒ Object
Called on Ctrl-\ signal This method should be principally used for long action like running all specs/tests/...
-
#run_on_change(paths) ⇒ Object
Called on file(s) modifications.
-
#start ⇒ Object
Called once when Guard starts Please override initialize method to init stuff.
-
#stop ⇒ Object
Called on Ctrl-C signal (when Guard quits).
- #write(output, str) ⇒ Object
Constructor Details
#initialize(watchers = [], options = {}) ⇒ CoffeeDripper
Returns a new instance of CoffeeDripper.
20 21 22 23 24 25 26 27 28 |
# File 'lib/guard/coffeedripper.rb', line 20 def initialize(watchers=[], ={}) super @watchers, @options = watchers, @options[:output] ||= 'app/assets/' @options[:input] ||= 'app/beans/' @options[:ext] ||= 'bean' @options[:config] ||= 'config/coffee-dripper.yaml' load_config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/guard/coffeedripper.rb', line 8 def config @config end |
Class Method Details
.init(guard_name = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/guard/coffeedripper.rb', line 9 def self.init(guard_name = nil) super(guard_name) if !File.exist?("config/coffeedripper.yaml") puts "Writing new Guardfile to #{Dir.pwd}/config/coffee-dripper.yaml" FileUtils.cp(File.('../coffeedripper/templates/coffee-dripper.yaml', __FILE__), 'config/coffee-dripper.yaml') elsif guard_name.nil? ::Guard::UI.error "Guardfile already exists at #{Dir.pwd}/config/coffee-dripper.yaml" exit 1 end end |
Instance Method Details
#change_bean(bean) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/guard/coffeedripper.rb', line 36 def change_bean(bean) @config.each do |coffee, beans| if beans.include? bean drip(coffee) end end end |
#drip(coffee_script) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/guard/coffeedripper.rb', line 51 def drip(coffee_script) puts "Drip Start for #{coffee_script}" beans = @config[coffee_script] output = File.join Dir.pwd, @options[:output], coffee_script str = "" beans.each do |bean| str += load_bean(bean) end write(output, str) puts "Drip End #{output}" end |
#drip_all ⇒ Object
44 45 46 47 48 49 |
# File 'lib/guard/coffeedripper.rb', line 44 def drip_all puts "Drip Start for All" @config.each do |coffee, beans| drip(coffee) end end |
#load_bean(bean) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/guard/coffeedripper.rb', line 63 def load_bean(bean) str = "" input = File.join Dir.pwd, @options[:input], bean f = open(input) str = f.read f.close str << "\n" end |
#load_coffee(coffee) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/guard/coffeedripper.rb', line 72 def load_coffee(coffee) str = "" output = File.join Dir.pwd, @options[:output], coffee f = open(output) str = f.read f.close return str end |
#load_config ⇒ Object
30 31 32 33 34 |
# File 'lib/guard/coffeedripper.rb', line 30 def load_config @config = YAML.load_file File.join Dir.pwd, @options[:config] return true if @config return false end |
#reload ⇒ Object
Called on Ctrl-Z signal This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
106 107 108 109 |
# File 'lib/guard/coffeedripper.rb', line 106 def reload load_config run_all end |
#run_all ⇒ Object
Called on Ctrl-\ signal This method should be principally used for long action like running all specs/tests/...
113 114 115 |
# File 'lib/guard/coffeedripper.rb', line 113 def run_all drip_all end |
#run_on_change(paths) ⇒ Object
Called on file(s) modifications
118 119 120 121 122 |
# File 'lib/guard/coffeedripper.rb', line 118 def run_on_change(paths) paths.each do |bean| change_bean(bean.split("/").last) end end |
#start ⇒ Object
Called once when Guard starts Please override initialize method to init stuff
95 96 97 |
# File 'lib/guard/coffeedripper.rb', line 95 def start run_all end |
#stop ⇒ Object
Called on Ctrl-C signal (when Guard quits)
100 101 102 |
# File 'lib/guard/coffeedripper.rb', line 100 def stop true end |
#write(output, str) ⇒ Object
81 82 83 84 85 |
# File 'lib/guard/coffeedripper.rb', line 81 def write(output,str) f = File.open(output,'w') f.puts str f.close end |