Object
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
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 18 def initialize(opts = {}) @options = ::Guard::Options.new([:guardfile, :guardfile_contents].reduce({}) { |h, key| h[key] = opts[key]; h }) end
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 33 def evaluate_guardfile _fetch_guardfile_contents _instance_eval_guardfile(guardfile_contents) end
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 99 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
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 59 def guardfile_include?(plugin_name) _guardfile_contents_without_user_config.match(/^guard\s*\(?\s*['":]#{ plugin_name }['"]?/) end
Gets the file path to the project `Guardfile`.
@example Gets the path of the currently evaluated Guardfile
Dir.pwd #=> "/Users/remy/Code/github/guard" evaluator = Guard::Guardfile::Evaluator.new evaluator.evaluate_guardfile #=> nil evaluator.guardfile_path #=> "/Users/remy/Code/github/guard/Guardfile"
@example Gets the "path" of an inline Guardfile
> Guard::Guardfile::Evaluator.new(guardfile_contents: 'guard :rspec').evaluate_guardfile => nil > Guard::Guardfile::Evaluator.new.guardfile_path => "Inline Guardfile"
@return [String] the path to the Guardfile or 'Inline Guardfile' if
the Guardfile has been specified via the `:guardfile_contents` option.
# File lib/guard/guardfile/evaluator.rb, line 86 def guardfile_path options.guardfile_path || '' end
Re-evaluates the `Guardfile` to update the current Guard configuration.
# File lib/guard/guardfile/evaluator.rb, line 41 def reevaluate_guardfile _before_reevaluate_guardfile evaluate_guardfile _after_reevaluate_guardfile end
Generated with the Darkfish Rdoc Generator 2.