Sha256: 655f000c1c0c3889d00a027ef6b66124dbc41cdc575d0d9b6e63c7630b3901a2

Contents?: true

Size: 534 Bytes

Versions: 10

Compression:

Stored size: 534 Bytes

Contents

# frozen_string_literal: true
module Temple
  module Filters
    # Erase expressions with a certain type
    #
    # @api public
    class Eraser < Filter
      # [] is the empty type => keep all
      define_options :erase, keep: [[]]

      def compile(exp)
        exp.first == :multi || (do?(:keep, exp) && !do?(:erase, exp)) ?
          super(exp) : [:multi]
      end

      protected

      def do?(list, exp)
        options[list].to_a.map {|type| [*type] }.any? {|type| exp[0,type.size] == type }
      end
    end
  end
end

Version data entries

10 entries across 9 versions & 3 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/filters/eraser.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/temple-0.10.3/lib/temple/filters/eraser.rb
brakeman-7.0.0 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/filters/eraser.rb
brakeman-6.2.2 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/filters/eraser.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/temple-0.10.3/lib/temple/filters/eraser.rb
brakeman-6.2.1 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/filters/eraser.rb
brakeman-6.2.0 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/filters/eraser.rb
temple-0.10.3 lib/temple/filters/eraser.rb
temple-0.10.2 lib/temple/filters/eraser.rb
temple-0.10.1 lib/temple/filters/eraser.rb