Class: Guard::DslDescriber
- Inherits:
-
Object
- Object
- Guard::DslDescriber
- 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`.
Instance Method Summary collapse
-
#initialize(options = nil) ⇒ DslDescriber
constructor
A new instance of DslDescriber.
-
#list ⇒ Object
List the Guard plugins that are available for use in your system and marks those that are currently used in your ‘Guardfile`.
-
#notifiers ⇒ Object
Shows all notifiers and their options that are defined in the ‘Guardfile`.
-
#show ⇒ Object
Shows all Guard plugins and their options that are defined in the ‘Guardfile`.
Constructor Details
#initialize(options = nil) ⇒ DslDescriber
Returns a new instance of DslDescriber.
19 20 21 |
# File 'lib/guard/dsl_describer.rb', line 19 def initialize( = nil) fail "options passed to DslDescriber are ignored!" unless .nil? end |
Instance Method Details
#list ⇒ Object
List the Guard plugins that are available for use in your system and marks those that are currently used in your ‘Guardfile`.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/guard/dsl_describer.rb', line 28 def list # TODO: remove dependency on Guard in this whole file # collect metadata data = PluginUtil.plugin_names.sort.inject({}) do |hash, name| hash[name.capitalize] = Guard.state.session.plugins.all(name).any? hash end # presentation header = [:Plugin, :Guardfile] final_rows = [] data.each do |name, used| final_rows << { Plugin: name, Guardfile: used ? "✔" : "✘" } end # render Formatador.display_compact_table(final_rows, header) end |
#notifiers ⇒ Object
Shows all notifiers and their options that are defined in the ‘Guardfile`.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/guard/dsl_describer.rb', line 108 def notifiers supported = Notifier.supported Notifier.connect(notify: true, silent: true) detected = Notifier.detected Notifier.disconnect detected_names = detected.map { |item| item[:name] } final_rows = supported.each_with_object([]) do |(name, _), rows| available = detected_names.include?(name) ? "✔" : "✘" notifier = detected.detect { |n| n[:name] == name } used = notifier ? "✔" : "✘" = notifier ? notifier[:options] : {} if .empty? rows << :split _add_row(rows, name, available, used, "", "") else .each_with_index do |(option, value), index| if index == 0 rows << :split _add_row(rows, name, available, used, option.to_s, value.inspect) else _add_row(rows, "", "", "", option.to_s, value.inspect) end end end rows end Formatador.display_compact_table( final_rows.drop(1), [:Name, :Available, :Used, :Option, :Value] ) end |
#show ⇒ Object
Shows all Guard plugins and their options that are defined in the ‘Guardfile`.
52 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/guard/dsl_describer.rb', line 52 def show # collect metadata groups = Guard.state.session.groups.all objects = [] empty_plugin = OpenStruct.new empty_plugin. = [["", nil]] groups.each do |group| plugins = Array(Guard.state.session.plugins.all(group: group.name)) plugins = [empty_plugin] if plugins.empty? plugins.each do |plugin| = plugin. = [["", nil]] if .empty? .each do |option, raw_value| value = raw_value.nil? ? "" : raw_value.inspect objects << [group.title, plugin.title, option.to_s, value] end end end # presentation rows = [] prev_group = prev_plugin = prev_option = prev_value = nil objects.each do |group, plugin, option, value| group_changed = prev_group != group plugin_changed = (prev_plugin != plugin || group_changed) rows << :split if group_changed || plugin_changed rows << { Group: group_changed ? group : "", Plugin: plugin_changed ? plugin : "", Option: option, Value: value } prev_group = group prev_plugin = plugin prev_option = option prev_value = value end # render Formatador.display_compact_table( rows.drop(1), [:Group, :Plugin, :Option, :Value] ) end |