class Guard::Preserves

Attributes

app_root[R]
destination[R]

Public Class Methods

new(watchers = [], options = {}) click to toggle source

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!

@param [Array<Guard::Watcher>] watchers the Guard plugin file watchers @param [Hash] options the custom Guard plugin options @option options [Symbol] group the group this Guard plugin belongs to @option options [Boolean] any_return allow any object to be returned from a watcher

Calls superclass method
# File lib/guard/preserves.rb, line 17
def initialize(watchers = [], options = {})
  @destination = options[:destination]
  @app_root = options[:app_root] || File.dirname(::Guard.options[:guardfile])
  watchers = [::Guard::Watcher.new(%r{^.+\.(js|coffee)$})] if watchers.empty?

  super
end

Public Instance Methods

reload() click to toggle source

Called when `reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…

@raise [:task_has_failed] when reload has failed @return [Object] the task result

# File lib/guard/preserves.rb, line 47
def reload
end
run_all() click to toggle source

Called when just `enter` is pressed This method should be principally used for long action like running all specs/tests/…

@raise [:task_has_failed] when run_all has failed @return [Object] the task result

# File lib/guard/preserves.rb, line 56
def run_all
end
run_on_additions(paths) click to toggle source

Called on file(s) additions that the Guard plugin watches.

@param [Array<String>] paths the changes files or paths @raise [:task_has_failed] when run_on_additions has failed @return [Object] the task result

# File lib/guard/preserves.rb, line 73
def run_on_additions(paths)
end
run_on_changes(paths) click to toggle source

Default behaviour on file(s) changes that the Guard plugin watches. @param [Array<String>] paths the changes files or paths @raise [:task_has_failed] when run_on_change has failed @return [Object] the task result

# File lib/guard/preserves.rb, line 64
def run_on_changes(paths)
end
run_on_modifications(paths) click to toggle source

Called on file(s) modifications that the Guard plugin watches.

@param [Array<String>] paths the changes files or paths @raise [:task_has_failed] when run_on_modifications has failed @return [Object] the task result

# File lib/guard/preserves.rb, line 82
def run_on_modifications(paths)
  paths.each do |path|
    package = package_name(path)
    compile_package package if File.extname(path) == '.coffee'
    copy_package package if File.extname(path) == '.js'
  end
end
run_on_removals(paths) click to toggle source

Called on file(s) removals that the Guard plugin watches.

@param [Array<String>] paths the changes files or paths @raise [:task_has_failed] when run_on_removals has failed @return [Object] the task result

# File lib/guard/preserves.rb, line 96
def run_on_removals(paths)
end
start() click to toggle source

Called once when Guard starts. Please override initialize method to init stuff.

@raise [:task_has_failed] when start has failed @return [Object] the task result

# File lib/guard/preserves.rb, line 30
def start
end
stop() click to toggle source

Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).

@raise [:task_has_failed] when stop has failed @return [Object] the task result

# File lib/guard/preserves.rb, line 38
def stop
end

Private Instance Methods

compile_package(package) click to toggle source
# File lib/guard/preserves.rb, line 104
def compile_package(package)
  ::Guard::UI.info "Compiling #{package}"
  Dir.chdir package
  `coffee -c --output ./ src/`
  Dir.chdir '..'
end
copy_package(package) click to toggle source
# File lib/guard/preserves.rb, line 111
def copy_package(package)
    package_destination = File.join(app_root, destination, package)
    ::Guard::UI.info "Copying #{package} to #{package_destination}"
    FileUtils.mkdir_p package_destination
    FileUtils.cp_r("#{package}/.", package_destination)
end
package_name(path) click to toggle source
# File lib/guard/preserves.rb, line 100
def package_name(path)
  path.split('/').first
end