Sha256: 35b27af2df3117572a190883015144f69ee9bb109d40a28144f671d45cad9916

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

module SassListen
  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

13 entries across 13 versions & 3 rubygems

Version Path
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/sass-listen-4.0.0/lib/sass-listen/silencer/controller.rb
sass-listen-4.0.0 lib/sass-listen/silencer/controller.rb