Module: Guard

Extended by:
Commander, DeprecatedMethods, Setuper
Defined in:
lib/guard.rb,
lib/guard/ui.rb,
lib/guard/cli.rb,
lib/guard/dsl.rb,
lib/guard/group.rb,
lib/guard/guard.rb,
lib/guard/plugin.rb,
lib/guard/runner.rb,
lib/guard/setuper.rb,
lib/guard/version.rb,
lib/guard/watcher.rb,
lib/guard/options.rb,
lib/guard/notifier.rb,
lib/guard/rake_task.rb,
lib/guard/guardfile.rb,
lib/guard/commander.rb,
lib/guard/ui/colors.rb,
lib/guard/deprecator.rb,
lib/guard/interactor.rb,
lib/guard/plugin_util.rb,
lib/guard/plugin/base.rb,
lib/guard/commands/all.rb,
lib/guard/plugin/hooker.rb,
lib/guard/commands/show.rb,
lib/guard/dsl_describer.rb,
lib/guard/notifiers/gntp.rb,
lib/guard/commands/scope.rb,
lib/guard/notifiers/tmux.rb,
lib/guard/commands/pause.rb,
lib/guard/notifiers/base.rb,
lib/guard/commands/reload.rb,
lib/guard/commands/change.rb,
lib/guard/notifiers/emacs.rb,
lib/guard/notifiers/growl.rb,
lib/guard/deprecated_methods.rb,
lib/guard/notifiers/libnotify.rb,
lib/guard/guardfile/evaluator.rb,
lib/guard/guardfile/generator.rb,
lib/guard/notifiers/rb_notifu.rb,
lib/guard/notifiers/notifysend.rb,
lib/guard/commands/notification.rb,
lib/guard/notifiers/growl_notify.rb,
lib/guard/notifiers/file_notifier.rb,
lib/guard/notifiers/terminal_title.rb,
lib/guard/notifiers/terminal_notifier.rb

Overview

Guard is the main module for all Guard related modules and classes. Also Guard plugins should use this namespace.

Defined Under Namespace

Modules: Commander, DeprecatedMethods, Guardfile, Notifier, Setuper, UI Classes: CLI, Deprecator, Dsl, DslDescriber, Group, Guard, Interactor, Options, Plugin, PluginUtil, RakeTask, Runner, Watcher

Constant Summary

WINDOWS =
RbConfig::CONFIG['host_os'] =~ %r!(msdos|mswin|djgpp|mingw)!
DEV_NULL =
WINDOWS ? 'NUL' : '/dev/null'
VERSION =
'2.6.0'

Constants included from Setuper

Setuper::DEFAULT_GROUPS, Setuper::DEFAULT_OPTIONS

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Setuper

clear_options, evaluate_guardfile, evaluator, interactor, options, reset_groups, reset_plugins, reset_scope, setup, setup_scope

Methods included from DeprecatedMethods

add_guard, get_guard_class, guard_gem_names, guards, locate_guard

Methods included from Commander

pause, reload, run_all, start, stop, within_preserved_state

Class Attribute Details

.listenerObject

Returns the value of attribute listener



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

def listener
  @listener
end

.lockObject

Returns the value of attribute lock



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

def lock
  @lock
end

.runnerObject

Returns the value of attribute runner



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

def runner
  @runner
end

.runningObject

Returns the value of attribute running



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

def running
  @running
end

.scopeObject

Returns the value of attribute scope



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

def scope
  @scope
end

Class Method Details

.add_group(name, options = {}) ⇒ Group

Add a Guard plugin group.

Parameters:

  • name (String)

    the group name

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

    a customizable set of options

Options Hash (options):

  • halt_on_fail (Boolean)

    if a task execution should be halted for all Guard plugins in this group if one Guard throws `:task_has_failed`

Returns:

  • (Group)

    the group added (or retrieved from the `@groups` variable if already present)

See Also:



184
185
186
187
188
189
190
191
# File 'lib/guard.rb', line 184

def add_group(name, options = {})
  unless group = group(name)
    group = ::Guard::Group.new(name, options)
    @groups << group
  end

  group
end

.add_plugin(name, options = {}) ⇒ Plugin

Add a Guard plugin to use.

Parameters:

  • name (String)

    the Guard name

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

    the plugin options (see the given Guard documentation)

Options Hash (options):

  • group (String)

    the group to which the Guard plugin belongs

  • watchers (Array<Watcher>)

    the list of declared watchers

  • callbacks (Array<Hash>)

    the list of callbacks

Returns:

  • (Plugin)

    the added Guard plugin

See Also:



166
167
168
169
170
171
# File 'lib/guard.rb', line 166

def add_plugin(name, options = {})
  plugin_instance = ::Guard::PluginUtil.new(name).initialize_plugin(options)
  @plugins << plugin_instance

  plugin_instance
end

.group(filter) ⇒ Group

Smart accessor for retrieving a specific group.

Examples:

Find a group by String or Symbol

Guard.group('backend')
Guard.group(:backend)

Find a group by Regexp

Guard.group(/(back|front)end/)

Parameters:

  • filter (String, Symbol, Regexp)

    the filter for finding the group

Returns:

  • (Group)

    the group found, nil otherwise

See Also:



152
153
154
# File 'lib/guard.rb', line 152

def group(filter)
  groups(filter).first
end

.groups(filter = nil) ⇒ Array<Group>

Smart accessor for retrieving specific groups at once.

Examples:

Filter groups by String or Symbol

Guard.groups('backend')
Guard.groups(:backend)

Filter groups by Regexp

Guard.groups(/(back|front)end/)

Parameters:

  • filter (String, Symbol, Regexp) (defaults to: nil)

    the filter to apply to the Groups

Returns:

  • (Array<Group>)

    the filtered group(s)

See Also:



121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/guard.rb', line 121

def groups(filter = nil)
  @groups ||= []

  return @groups if filter.nil?

  filtered_groups = case filter
                    when String, Symbol
                      @groups.find_all { |group| group.name == filter.to_sym }
                    when Regexp
                      @groups.find_all { |group| group.name.to_s =~ filter }
                    end

  filtered_groups
end

.plugin(filter) ⇒ Plugin?

Smart accessor for retrieving a specific plugin.

Examples:

Find a plugin by String or Symbol

Guard.plugin('rspec')
Guard.plugin(:rspec)

Find a plugin by Regexp

Guard.plugin(/rsp.+/)

Find a plugin by Hash

Guard.plugin(name: 'rspec', group: 'backend')

Parameters:

  • filter (String, Symbol, Regexp, Hash)

    the filter for finding the plugin the Guard plugin

Returns:

  • (Plugin, nil)

    the plugin found, nil otherwise

See Also:



101
102
103
# File 'lib/guard.rb', line 101

def plugin(filter)
  plugins(filter).first
end

.plugins(filter = nil) ⇒ Plugin+

Smart accessor for retrieving specific plugins at once.

Examples:

Filter plugins by String or Symbol

Guard.plugins('rspec')
Guard.plugins(:rspec)

Filter plugins by Regexp

Guard.plugins(/rsp.+/)

Filter plugins by Hash

Guard.plugins(name: 'rspec', group: 'backend')

Parameters:

  • filter (String, Symbol, Regexp, Hash) (defaults to: nil)

    the filter to apply to the plugins

Returns:

See Also:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/guard.rb', line 51

def plugins(filter = nil)
  @plugins ||= []

  return @plugins if filter.nil?

  filtered_plugins = case filter
                    when String, Symbol
                      @plugins.find_all do |plugin|
                        plugin.name == filter.to_s.downcase.gsub('-', '')
                      end
                    when Regexp
                      @plugins.find_all do |plugin|
                        plugin.name =~ filter
                      end
                    when Hash
                      @plugins.find_all do |plugin|
                        filter.all? do |k, v|
                          case k
                          when :name
                            plugin.name == v.to_s.downcase.gsub('-', '')
                          when :group
                            plugin.group.name == v.to_sym
                          end
                        end
                      end
                    end

  filtered_plugins
end