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
- 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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/guard/guardfile/evaluator.rb', line 51 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(opts[:guardfile]) # may be updated by _read end end |
Instance Attribute Details
#guardfile_path ⇒ Object (readonly)
Returns the value of attribute guardfile_path.
24 25 26 |
# File 'lib/guard/guardfile/evaluator.rb', line 24 def guardfile_path @guardfile_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
24 25 26 |
# File 'lib/guard/guardfile/evaluator.rb', line 24 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
113 114 115 |
# File 'lib/guard/guardfile/evaluator.rb', line 113 def path @path end |
Instance Method Details
#custom? ⇒ Boolean
115 116 117 |
# File 'lib/guard/guardfile/evaluator.rb', line 115 def custom? @type == :custom end |
#evaluate ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/guard/guardfile/evaluator.rb', line 83 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.
128 129 130 131 |
# File 'lib/guard/guardfile/evaluator.rb', line 128 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
107 108 109 110 111 |
# File 'lib/guard/guardfile/evaluator.rb', line 107 def guardfile_include?(plugin_name) reader = DslReader.new reader.evaluate(@contents, @path || "", 1) reader.plugin_names.include?(plugin_name) end |
#guardfile_source ⇒ Object
41 42 43 |
# File 'lib/guard/guardfile/evaluator.rb', line 41 def guardfile_source @source end |
#inline? ⇒ Boolean
133 134 135 |
# File 'lib/guard/guardfile/evaluator.rb', line 133 def inline? @type == :inline end |