Class: Guard::Reek

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/reek.rb,
lib/guard/reek/runner.rb

Overview

Guard::Reek class, it implements an guard for reek task

Defined Under Namespace

Classes: Runner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Reek

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



17
18
19
20
21
22
23
# File 'lib/guard/reek.rb', line 17

def initialize(options = {})
  super

  @options = { all_on_start: true, run_all: true }.merge(options)
  @runner = @options[:runner] || Runner.new(options)
  @ui = @options[:ui] || UI
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#runnerObject (readonly)

Returns the value of attribute runner.



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

def runner
  @runner
end

#uiObject (readonly)

Returns the value of attribute ui.



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

def ui
  @ui
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



59
60
61
62
63
64
65
66
67
68
# File 'lib/guard/reek.rb', line 59

def run_all
  if options[:run_all]
    ui.info('Guard::Reek is running on all files')
    runner.run
  else
    ui.info('Guard::Reek is not allowed to run on all files')
  end
rescue
  throw :task_has_failed
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



76
77
78
79
80
# File 'lib/guard/reek.rb', line 76

def run_on_additions(paths)
  runner.run paths
rescue
  throw :task_has_failed
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



88
89
90
91
92
# File 'lib/guard/reek.rb', line 88

def run_on_modifications(paths)
  runner.run paths
rescue
  throw :task_has_failed
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
32
33
34
# File 'lib/guard/reek.rb', line 30

def start
  runner.run if options[:all_on_start]
rescue
  throw :task_has_failed
end