Sha256: 6591cfb39ffdfaad5ed9a403eaa84927a9f31ae2b39c57559239bc714fe70cf9

Contents?: true

Size: 1.2 KB

Versions: 111

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Listen
  class Silencer
    class Controller
      def initialize(silencer, default_options)
        @silencer = silencer

        opts = default_options

        @prev_silencer_options = {}
        rules = [:only, :ignore, :ignore!].map do |option|
          [option, opts[option]] if opts.key? option
        end

        _reconfigure_silencer(Hash[rules.compact])
      end

      def append_ignores(*regexps)
        prev_ignores = Array(@prev_silencer_options[:ignore])
        _reconfigure_silencer(ignore: [prev_ignores + regexps])
      end

      def replace_with_bang_ignores(regexps)
        _reconfigure_silencer(ignore!: regexps)
      end

      def replace_with_only(regexps)
        _reconfigure_silencer(only: regexps)
      end

      private

      def _reconfigure_silencer(extra_options)
        opts = extra_options.dup
        opts = opts.map do |key, value|
          [key, Array(value).flatten.compact]
        end
        opts = Hash[opts]

        if opts.key?(:ignore) && opts[:ignore].empty?
          opts.delete(:ignore)
        end

        @prev_silencer_options = opts
        @silencer.configure(@prev_silencer_options.dup.freeze)
      end
    end
  end
end

Version data entries

111 entries across 110 versions & 7 rubygems

Version Path
harbr-0.1.91 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.90 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.89 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.88 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.87 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.86 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.85 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.84 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.83 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.82 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.81 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.80 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.79 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.78 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.77 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.76 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.75 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.74 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.73 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb
harbr-0.1.72 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/silencer/controller.rb