Class: Guard::Concat
Constant Summary collapse
- VERSION =
'0.0.2'
Instance Method Summary collapse
- #concat ⇒ Object
-
#initialize(watchers = [], opts = {}) ⇒ Concat
constructor
A new instance of Concat.
-
#run_on_changes(paths) ⇒ Object
# Call #run_on_change for all files which match this guard.
Constructor Details
#initialize(watchers = [], opts = {}) ⇒ Concat
Returns a new instance of Concat.
10 11 12 13 14 15 16 17 18 |
# File 'lib/guard/concat.rb', line 10 def initialize(watchers=[], opts={}) @output = "#{opts[:output]}.#{opts[:type]}" files = opts[:files].join("|") regex = %r{^#{opts[:input_dir]}/(#{files})\.#{opts[:type]}$} watcher = ::Guard::Watcher.new regex watchers << watcher @watchers, @opts = watchers, opts super watchers, opts end |
Instance Method Details
#concat ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/guard/concat.rb', line 35 def concat content = "" files = [] @opts[:files].each do |file| files << "#{@opts[:input_dir]}/#{file}.#{@opts[:type]}" end files.each do |file| content << File.read(file) content << "\n" end File.open(@output, "w"){ |f| f.write content.strip } end |
#run_on_changes(paths) ⇒ Object
# Call #run_on_change for all files which match this guard. def run_all
run_on_changes(Watcher.match_files(self, Dir.glob('{,**/}*{,.*}').uniq))
end
30 31 32 33 |
# File 'lib/guard/concat.rb', line 30 def run_on_changes(paths) concat UI.info "Concatenated #{@output}" end |