Class: Guard::DslDescriber

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

Overview

The DslDescriber evaluates the Guardfile and creates an internal structure of it that is used in some inspection utility methods like the CLI commands `show` and `list`.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DslDescriber

Initializes a new DslDescriber object.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • guardfile (String)

    the path to a valid Guardfile

  • guardfile_contents (String)

    a string representing the content of a valid Guardfile

See Also:



27
28
29
30
31
# File 'lib/guard/dsl_describer.rb', line 27

def initialize(options = {})
  @options = options
  ::Guard.reset_groups
  ::Guard.reset_plugins
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options



18
19
20
# File 'lib/guard/dsl_describer.rb', line 18

def options
  @options
end

Instance Method Details

#listObject

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

See Also:



38
39
40
41
42
43
44
45
46
# File 'lib/guard/dsl_describer.rb', line 38

def list
  _evaluate_guardfile

  rows = ::Guard::PluginUtil.plugin_names.sort.uniq.inject([]) do |rows, name|
    rows << { Plugin: name.capitalize, Guardfile: ::Guard.plugins(name) ? '' : '' }
  end

  Formatador.display_compact_table(rows, [:Plugin, :Guardfile])
end

#notifiersObject

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

See Also:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/guard/dsl_describer.rb', line 86

def notifiers
  _evaluate_guardfile

  rows = ::Guard::Notifier::NOTIFIERS.inject(:merge).inject([]) do |rows, definition|
    name      = definition[0]
    clazz     = definition[1]
    available = clazz.available?(silent: true) ? '' : ''
    notifier  = ::Guard::Notifier.notifiers.find { |n| n[:name] == name }
    used      = notifier ? '' : ''
    options   = notifier ? notifier[:options] : {}
    defaults  = clazz.const_defined?(:DEFAULTS) ? clazz.const_get(:DEFAULTS) : {}
    options   = defaults.merge(options)
    options.delete(:silent)

    if options.empty?
      rows << :split
      rows << { Name: name, Available: available, Used: used, Option: '', Value: '' }
    else
      options.each_with_index do |(option, value), index|
        if index == 0
          rows << :split
          rows << { Name: name, Available: available, Used: used, Option: option.to_s, Value: value.inspect }
        else
          rows << { Name: '', Available: '', Used: '', Option: option.to_s, Value: value.inspect }
        end
      end
    end

    rows
  end

  Formatador.display_compact_table(rows.drop(1), [:Name, :Available, :Used, :Option, :Value])
end

#showObject

Shows all Guard plugins and their options that are defined in the `Guardfile`.

See Also:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/guard/dsl_describer.rb', line 53

def show
  _evaluate_guardfile

  rows = ::Guard.groups.inject([]) do |rows, group|
    Array(::Guard.plugins(group: group.name)).each do |plugin|
      options = plugin.options.inject({}) { |o, (k, v)| o[k.to_s] = v; o }.sort

      if options.empty?
        rows << :split
        rows << { Group: group.title, Plugin: plugin.title, Option: '', Value: '' }
      else
        options.each_with_index do |(option, value), index|
          if index == 0
            rows << :split
            rows << { Group: group.title, Plugin: plugin.title, Option: option.to_s, Value: value.inspect }
          else
            rows << { Group: '', Plugin: '', Option: option.to_s, Value: value.inspect }
          end
        end
      end
    end

    rows
  end

  Formatador.display_compact_table(rows.drop(1), [:Group, :Plugin, :Option, :Value])
end