Parent

Files

Guard::Interactor

The Guard interactor is a Pry REPL with a Guard specific command set.

Constants

ALL
CHANGE
GUARD_RC

The default Ruby script to configure Guard Pry if the option `:guard_rc` is not defined.

HISTORY_FILE

The default Guard Pry history file if the option `:history_file` is not defined.

NOTIFICATION
PAUSE
RELOAD
SCOPE
SHORTCUTS

List of shortcuts for each interactor command

SHOW

Attributes

thread[RW]

Public Class Methods

convert_scope(entries) click to toggle source

Converts and validates a plain text scope to a valid plugin or group scope.

@param [Array<String>] entries the text scope @return [Hash, Array<String>] the plugin or group scope, the unknown entries

# File lib/guard/interactor.rb, line 81
def self.convert_scope(entries)
  scopes  = { plugins: [], groups: [] }
  unknown = []

  entries.each do |entry|
    if plugin = ::Guard.plugin(entry)
      scopes[:plugins] << plugin
    elsif group = ::Guard.group(entry)
      scopes[:groups] << group
    else
      unknown << entry
    end
  end

  [scopes, unknown]
end
enabled() click to toggle source

Is the interactor enabled?

@return [Boolean] true if enabled

# File lib/guard/interactor.rb, line 63
def self.enabled
  @enabled || @enabled.nil?
end
enabled=(status) click to toggle source

Set the enabled status for the interactor

@param [Boolean] status true if enabled

# File lib/guard/interactor.rb, line 71
def self.enabled=(status)
  @enabled = status
end
new() click to toggle source

Initializes the interactor. This configures Pry and creates some custom commands and aliases for Guard.

# File lib/guard/interactor.rb, line 102
def initialize
  return if ENV['GUARD_ENV'] == 'test'

  Pry.config.should_load_rc       = false
  Pry.config.should_load_local_rc = false
  Pry.config.history.file         = File.expand_path(self.class.options[:history_file] || HISTORY_FILE)

  @stty_exists = nil
  _add_hooks

  _replace_reset_command
  _create_run_all_command
  _create_command_aliases
  _create_guard_commands
  _create_group_commands

  _configure_prompt
end
options() click to toggle source

Get the interactor options

@return [Hash] the options

# File lib/guard/interactor.rb, line 45
def self.options
  @options ||= {}
end
options=(options) click to toggle source

Set the interactor options

@param [Hash] options the interactor options @option options [String] :guard_rc the Ruby script to configure Guard Pry @option options [String] :history_file the file to write the Pry history to

# File lib/guard/interactor.rb, line 55
def self.options=(options)
  @options = options
end

Public Instance Methods

start() click to toggle source

Start the line reader in its own thread and stop Guard on Ctrl-D.

# File lib/guard/interactor.rb, line 124
def start
  return if ENV['GUARD_ENV'] == 'test'

  _store_terminal_settings if _stty_exists?

  unless @thread
    ::Guard::UI.debug 'Start interactor'

    @thread = Thread.new do
      Pry.start
      ::Guard.stop
    end
  end
end
stop() click to toggle source

Kill interactor thread if not current

# File lib/guard/interactor.rb, line 141
def stop
  return if !@thread || ENV['GUARD_ENV'] == 'test'

  unless Thread.current == @thread
    ::Guard::UI.reset_line
    ::Guard::UI.debug 'Stop interactor'
    @thread.kill
    @thread = nil
  end

  _restore_terminal_settings if _stty_exists?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.