Class: Guard::Preserves

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/preserves.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ Preserves

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!

Parameters:

  • watchers (Array<Guard::Watcher>) (defaults to: [])

    the Guard plugin file watchers

  • options (Hash) (defaults to: {})

    the custom Guard plugin options

Options Hash (options):

  • group (Symbol)

    the group this Guard plugin belongs to

  • any_return (Boolean)

    allow any object to be returned from a watcher



17
18
19
20
21
22
23
# 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

Instance Attribute Details

#app_rootObject (readonly)

Returns the value of attribute app_root.



8
9
10
# File 'lib/guard/preserves.rb', line 8

def app_root
  @app_root
end

#destinationObject (readonly)

Returns the value of attribute destination.



8
9
10
# File 'lib/guard/preserves.rb', line 8

def destination
  @destination
end

Instance Method Details

#reloadObject

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

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when reload has failed



47
48
# File 'lib/guard/preserves.rb', line 47

def reload
end

#run_allObject

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

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_all has failed



56
57
# File 'lib/guard/preserves.rb', line 56

def run_all
end

#run_on_additions(paths) ⇒ Object

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

Parameters:

  • paths (Array<String>)

    the changes files or paths

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_on_additions has failed



73
74
# File 'lib/guard/preserves.rb', line 73

def run_on_additions(paths)
end

#run_on_changes(paths) ⇒ Object

Default behaviour on file(s) changes that the Guard plugin watches.

Parameters:

  • paths (Array<String>)

    the changes files or paths

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_on_change has failed



64
65
# File 'lib/guard/preserves.rb', line 64

def run_on_changes(paths)
end

#run_on_modifications(paths) ⇒ Object

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

Parameters:

  • paths (Array<String>)

    the changes files or paths

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_on_modifications has failed



82
83
84
85
86
87
88
# 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) ⇒ Object

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

Parameters:

  • paths (Array<String>)

    the changes files or paths

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_on_removals has failed



96
97
# File 'lib/guard/preserves.rb', line 96

def run_on_removals(paths)
end

#startObject

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

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when start has failed



30
31
# File 'lib/guard/preserves.rb', line 30

def start
end

#stopObject

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

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when stop has failed



38
39
# File 'lib/guard/preserves.rb', line 38

def stop
end