Class: Guard::Guardfile::Evaluator
- Inherits:
-
Object
- Object
- Guard::Guardfile::Evaluator
- Defined in:
- lib/guard/guardfile/evaluator.rb
Overview
This class is responsible for evaluating the Guardfile. It delegates to Guard::Dsl for the actual objects generation from the Guardfile content.
TODO: rename this to a Locator or Loader or something
Defined Under Namespace
Classes: Error, NoCustomGuardfile, NoGuardfileError, NoPluginsError
Constant Summary collapse
- DEFAULT_GUARDFILES =
%w( guardfile.rb Guardfile ~/.Guardfile ).freeze
- ERROR_NO_GUARDFILE =
"No Guardfile found,"\ " please create one with `guard init`."
- ERROR_NO_PLUGINS =
"No Guard plugins found in Guardfile,"\ " please add at least one."
Instance Attribute Summary collapse
-
#guardfile_path ⇒ Object
readonly
Returns the value of attribute guardfile_path.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #custom? ⇒ Boolean
-
#evaluate ⇒ Object
Evaluates the DSL methods in the ‘Guardfile`.
-
#guardfile_contents ⇒ String
Gets the content of the ‘Guardfile` concatenated with the global user configuration file.
-
#guardfile_include?(plugin_name) ⇒ Boolean
Tests if the current ‘Guardfile` contains a specific Guard plugin.
- #guardfile_source ⇒ Object
-
#initialize(opts = {}) ⇒ Evaluator
constructor
Initializes a new Guard::Guardfile::Evaluator object.
- #inline? ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ Evaluator
Initializes a new Guard::Guardfile::Evaluator object.
content of a valid Guardfile
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/guard/guardfile/evaluator.rb', line 57 def initialize(opts = {}) @type = nil @path = nil @user_config = nil opts = _from_deprecated(opts) if opts[:contents] @type = :inline @contents = opts[:contents] elsif opts[:guardfile] @type = :custom @path = Pathname.new(opts[:guardfile]) # may be updated by _read end end |
Instance Attribute Details
#guardfile_path ⇒ Object (readonly)
Returns the value of attribute guardfile_path.
30 31 32 |
# File 'lib/guard/guardfile/evaluator.rb', line 30 def guardfile_path @guardfile_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
30 31 32 |
# File 'lib/guard/guardfile/evaluator.rb', line 30 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
119 120 121 |
# File 'lib/guard/guardfile/evaluator.rb', line 119 def path @path end |
Instance Method Details
#custom? ⇒ Boolean
121 122 123 |
# File 'lib/guard/guardfile/evaluator.rb', line 121 def custom? @type == :custom end |
#evaluate ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/guard/guardfile/evaluator.rb', line 89 def evaluate inline? || _use_provided || _use_default! contents = _guardfile_contents fail NoPluginsError, ERROR_NO_PLUGINS unless /guard/m =~ contents Dsl.new.evaluate(contents, @path || "", 1) end |
#guardfile_contents ⇒ String
Gets the content of the ‘Guardfile` concatenated with the global user configuration file.
134 135 136 137 |
# File 'lib/guard/guardfile/evaluator.rb', line 134 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) ⇒ Boolean
Tests if the current ‘Guardfile` contains a specific Guard plugin.
plugin
File.read('Guardfile')
=> "guard :rspec"
Guard::Guardfile::Evaluator.new.guardfile_include?('rspec)
=> true
TODO: rename this method to it matches RSpec examples better
113 114 115 116 117 |
# File 'lib/guard/guardfile/evaluator.rb', line 113 def guardfile_include?(plugin_name) reader = DslReader.new reader.evaluate(@contents, @path || "", 1) reader.plugin_names.include?(plugin_name) end |
#guardfile_source ⇒ Object
47 48 49 |
# File 'lib/guard/guardfile/evaluator.rb', line 47 def guardfile_source @source end |
#inline? ⇒ Boolean
139 140 141 |
# File 'lib/guard/guardfile/evaluator.rb', line 139 def inline? @type == :inline end |