Parent

Files

Guard::Guardfile::Evaluator

This class is responsible for evaluating the Guardfile. It delegates to Guard::Dsl for the actual objects generation from the Guardfile content.

@see Guard::Dsl

Attributes

guardfile_path[R]
guardfile_source[R]
options[R]

Public Class Methods

new(opts = {}) click to toggle source

Initializes a new Guard::Guardfile::Evaluator object.

@option opts [String] guardfile the path to a valid Guardfile @option opts [String] guardfile_contents a string representing the content of a valid Guardfile

# File lib/guard/guardfile/evaluator.rb, line 20
def initialize(opts = {})
  @options = ::Guard::Options.new(opts.select { |k, _| [:guardfile, :guardfile_contents].include?(k.to_sym) })
end

Public Instance Methods

evaluate_guardfile() click to toggle source

Evaluates the DSL methods in the `Guardfile`.

@example Programmatically evaluate a Guardfile

Guard::Guardfile::Evaluator.new.evaluate_guardfile

@example Programmatically evaluate a Guardfile with a custom Guardfile path

Guard::Guardfile::Evaluator.new(guardfile: '/Users/guardfile/MyAwesomeGuardfile').evaluate_guardfile

@example Programmatically evaluate a Guardfile with an inline Guardfile

Guard::Guardfile::Evaluator.new(guardfile_contents: 'guard :rspec').evaluate_guardfile
# File lib/guard/guardfile/evaluator.rb, line 35
def evaluate_guardfile
  _fetch_guardfile_contents
  _instance_eval_guardfile(guardfile_contents)
end
guardfile_contents() click to toggle source

Gets the content of the `Guardfile` concatenated with the global user configuration file.

@example Programmatically get the content of the current Guardfile

Guard::Guardfile::Evaluator.new.guardfile_contents
=> "guard :rspec"

@return [String] the Guardfile content

# File lib/guard/guardfile/evaluator.rb, line 77
def guardfile_contents
  config = File.read(_user_config_path) if File.exist?(_user_config_path)
  [_guardfile_contents_without_user_config, config].compact.join("\n")
end
guardfile_include?(plugin_name) click to toggle source

Tests if the current `Guardfile` contains a specific Guard plugin.

@example Programmatically test if a Guardfile contains a specific Guard plugin

File.read('Guardfile')
=> "guard :rspec"

Guard::Guardfile::Evaluator.new.guardfile_include?('rspec)
=> true

@param [String] plugin_name the name of the Guard @return [Boolean] whether the Guard plugin has been declared

# File lib/guard/guardfile/evaluator.rb, line 64
def guardfile_include?(plugin_name)
  _guardfile_contents_without_user_config.match(/^guard\s*\(?\s*['":]#{ plugin_name }['"]?/)
end
reevaluate_guardfile() click to toggle source

Re-evaluates the `Guardfile` to update the current Guard configuration.

# File lib/guard/guardfile/evaluator.rb, line 43
def reevaluate_guardfile
  # Don't re-evaluate inline Guardfile
  return if @guardfile_source == :inline

  _before_reevaluate_guardfile
  evaluate_guardfile
  _after_reevaluate_guardfile
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.