class Guard::Internals::Session
TODO: swap session and metadata
TODO: split into a commandline class and session (plugins, groups)
def clearing(on)
def clearing(on) @clear = on end
def clearing?
def clearing? @clear end
def cmdline_groups
def cmdline_groups @cmdline_groups.dup.freeze end
def cmdline_plugins
def cmdline_plugins @cmdline_plugins.dup.freeze end
def convert_scope(entries)
def convert_scope(entries) scopes = { plugins: [], groups: [] } unknown = [] entries.each do |entry| if plugin = plugins.all(entry).first scopes[:plugins] << plugin elsif group = groups.all(entry).first scopes[:groups] << group else unknown << entry end end [scopes, unknown] end
def debug?
def debug? @debug end
def evaluator_options
def evaluator_options opts = { guardfile: @options[:guardfile] } # TODO: deprecate :guardfile_contents if @options[:guardfile_contents] opts[:contents] = @options[:guardfile_contents] end opts end
def guardfile_ignore=(ignores)
def guardfile_ignore=(ignores) @guardfile_ignore += Array(ignores).flatten end
def guardfile_notification=(config)
def guardfile_notification=(config) @guardfile_notifier_options.merge!(config) end
def guardfile_scope(scope)
def guardfile_scope(scope) opts = scope.dup groups = Array(opts.delete(:groups)) group = Array(opts.delete(:group)) @guardfile_group_scope = Array(groups) + Array(group) plugins = Array(opts.delete(:plugins)) plugin = Array(opts.delete(:plugin)) @guardfile_plugin_scope = Array(plugins) + Array(plugin) fail "Unknown options: #{opts.inspect}" unless opts.empty? end
def initialize(new_options)
def initialize(new_options) @options = Options.new(new_options, DEFAULT_OPTIONS) @plugins = Plugins.new @groups = Groups.new @cmdline_groups = @options[:group] @cmdline_plugins = @options[:plugin] @clear = @options[:clear] @debug = @options[:debug] @watchdirs = Array(@options[:watchdir]) @notify = @options[:notify] @interactor_name = @options[:no_interactions] ? :sleep : :pry_wrapper @guardfile_plugin_scope = [] @guardfile_group_scope = [] @guardfile_ignore = [] @guardfile_ignore_bang = [] @guardfile_notifier_options = {} end
def listener_args
def listener_args if @options[:listen_on] [:on, @options[:listen_on]] else listener_options = {} [:latency, :force_polling, :wait_for_delay].each do |option| listener_options[option] = @options[option] if @options[option] end expanded_watchdirs = watchdirs.map { |dir| File.expand_path dir } [:to, *expanded_watchdirs, listener_options] end end
def notify_options
def notify_options names = @guardfile_notifier_options.keys return { notify: false } if names.include?(:off) { notify: @options[:notify], notifiers: @guardfile_notifier_options } end
def watchdirs
def watchdirs @watchdirs_from_guardfile ||= nil @watchdirs_from_guardfile || @watchdirs end
def watchdirs=(dirs)
def watchdirs=(dirs) dirs = [Dir.pwd] if dirs.empty? @watchdirs_from_guardfile = dirs.map { |dir| File.expand_path dir } end