Class: Guard::Codespell

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/codespell.rb

Overview

Service that runs the codespell tool inside guard. Based on an example from the guard documentation github.com/guard/guard/wiki/Create-a-guard

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Codespell

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:

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

    the custom Guard plugin options

Options Hash (options):

  • watchers (Array<Guard::Watcher>)

    the Guard plugin file watchers

  • group (Symbol)

    the group this Guard plugin belongs to

  • any_return (Boolean)

    allow any object to be returned from a watcher



18
19
20
21
# File 'lib/guard/codespell.rb', line 18

def initialize(options = {})
  super
  @codespell = codespell_installed?
end

Instance Attribute Details

#codespellObject (readonly)

Returns the value of attribute codespell.



9
10
11
# File 'lib/guard/codespell.rb', line 9

def codespell
  @codespell
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/guard/codespell.rb', line 9

def options
  @options
end

Instance Method Details

#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



36
37
38
39
40
41
# File 'lib/guard/codespell.rb', line 36

def run_all
  return warn_codespell_missing unless codespell
  return run_codespell(changed_files) if options[:only_git_changes]

  run_codespell
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



48
49
50
51
52
# File 'lib/guard/codespell.rb', line 48

def run_on_additions(paths)
  return warn_codespell_missing unless codespell

  run_codespell(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



59
60
61
62
63
# File 'lib/guard/codespell.rb', line 59

def run_on_modifications(paths)
  return warn_codespell_missing unless codespell

  run_codespell(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



27
28
29
# File 'lib/guard/codespell.rb', line 27

def start
  run_all if options[:all_on_start]
end