Class: Guard::DslDescriber

Inherits:
Dsl
  • Object
show all
Defined in:
lib/guard/dsl_describer.rb

Overview

The DslDescriber overrides methods to create an internal structure of the Guardfile that is used in some inspection utility methods like the CLI commands ‘show` and `list`.

See Also:

Class Method Summary collapse

Methods inherited from Dsl

#callback, fetch_guardfile_contents, guardfile_contents, guardfile_contents_usable?, guardfile_contents_with_user_config, guardfile_default_path, guardfile_include?, guardfile_path, #ignore_paths, instance_eval_guardfile, read_guardfile, reevaluate_guardfile, #watch

Class Method Details

.evaluate_guardfile(options = {}) ⇒ Object

Evaluate the DSL methods in the ‘Guardfile`.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • groups (Array<Symbol,String>)

    the groups to evaluate

  • guardfile (String)

    the path to a valid Guardfile

  • guardfile_contents (String)

    a string representing the content of a valid Guardfile

Raises:

  • (ArgumentError)

    when options are not a Hash



25
26
27
28
# File 'lib/guard/dsl_describer.rb', line 25

def evaluate_guardfile(options = {})
  @@guardfile_structure = [{ :guards => [] }]
  super options
end

.list(options) ⇒ Object

List the Guards that are available for use in your system and marks those that are currently used in your ‘Guardfile`.

Examples:

Guard list output


Available guards:
  bundler *
  livereload
  ronn
  rspec *
  spork

See also https://github.com/guard/guard/wiki/List-of-available-Guards
* denotes ones already in your Guardfile

Parameters:

  • options (Hash)

    the Guard options



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/guard/dsl_describer.rb', line 47

def list(options)
  evaluate_guardfile(options)

  installed = guardfile_structure.inject([]) do |installed, group|
    group[:guards].each { |guard| installed << guard[:name] } if group[:guards]
    installed
  end

  UI.info 'Available guards:'

  ::Guard.guard_gem_names.sort.uniq.each do |name|
    UI.info "   #{ name }#{ installed.include?(name) ? '*' : '' }"
  end

  UI.info ''
  UI.info 'See also https://github.com/guard/guard/wiki/List-of-available-Guards'
  UI.info '* denotes ones already in your Guardfile'
end

.show(options) ⇒ Object

Shows all Guards and their options that are defined in the ‘Guardfile`.

Examples:

guard show output


(global):
  bundler
  coffeescript: input => "app/assets/javascripts", noop => true
  jasmine
  rspec: cli => "--fail-fast --format Fuubar

Parameters:

  • options (Hash)

    the Guard options



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/guard/dsl_describer.rb', line 79

def show(options)
  evaluate_guardfile(options)

  guardfile_structure.each do |group|
    unless group[:guards].empty?
      if group[:group]
        UI.info "Group #{ group[:group] }:"
      else
        UI.info '(global):'
      end

      group[:guards].each do |guard|
        line = "  #{ guard[:name] }"

        unless guard[:options].empty?
          line += ": #{ guard[:options].sort.collect { |k, v| "#{ k } => #{ v.inspect }" }.join(', ') }"
        end

        UI.info line
      end
    end
  end

  UI.info ''
end