# encoding: utf-8require'formatador'require'guard/guardfile/evaluator'require'guard/ui'moduleGuard# 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 Guard::Dsl# @see Guard::CLI#classDslDescriberattr_reader:options# Initializes a new DslDescriber object.## @option options [String] guardfile the path to a valid Guardfile# @option options [String] guardfile_contents a string representing the content of a valid Guardfile## @see Guard::Guardfile::Evaluator#initialize#definitialize(options={})@options=options::Guard.reset_groups::Guard.reset_pluginsend# List the Guard plugins that are available for use in your system and marks# those that are currently used in your `Guardfile`.## @see CLI#list#deflist_evaluate_guardfilerows=::Guard::PluginUtil.plugin_names.sort.uniq.inject([])do|rows,name|rows<<{Plugin:name.capitalize,Guardfile:::Guard.plugins(name)?'✔':'✘'}endFormatador.display_compact_table(rows,[:Plugin,:Guardfile])end# Shows all Guard plugins and their options that are defined in# the `Guardfile`.## @see CLI#show#defshow_evaluate_guardfilerows=::Guard.groups.inject([])do|rows,group|Array(::Guard.plugins(group: group.name)).eachdo|plugin|options=plugin.options.inject({}){|o,(k,v)|o[k.to_s]=v;o}.sortifoptions.empty?rows<<:splitrows<<{Group:group.title,Plugin:plugin.title,Option:'',Value:''}elseoptions.each_with_indexdo|(option,value),index|ifindex==0rows<<:splitrows<<{Group:group.title,Plugin:plugin.title,Option:option.to_s,Value:value.inspect}elserows<<{Group:'',Plugin:'',Option:option.to_s,Value:value.inspect}endendendendrowsendFormatador.display_compact_table(rows.drop(1),[:Group,:Plugin,:Option,:Value])end# Shows all notifiers and their options that are defined in# the `Guardfile`.## @see CLI#show#defnotifiers_evaluate_guardfilerows=::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)ifoptions.empty?rows<<:splitrows<<{Name:name,Available:available,Used:used,Option:'',Value:''}elseoptions.each_with_indexdo|(option,value),index|ifindex==0rows<<:splitrows<<{Name:name,Available:available,Used:used,Option:option.to_s,Value:value.inspect}elserows<<{Name:'',Available:'',Used:'',Option:option.to_s,Value:value.inspect}endendendrowsendFormatador.display_compact_table(rows.drop(1),[:Name,:Available,:Used,:Option,:Value])endprivate# Evaluates the `Guardfile` by delegating to# {Guard::Guardfile::Evaluator#evaluate_guardfile}.#def_evaluate_guardfile::Guard::Guardfile::Evaluator.new(options).evaluate_guardfileendendend