Sha256: ba29203b26db794e87df20aece4b17d59a13aeb270697b5722a1246ed1625aa4

Contents?: true

Size: 1004 Bytes

Versions: 34

Compression:

Stored size: 1004 Bytes

Contents

# frozen_string_literal: true

module DeepCover
  module Node::Mixin
    module Rewriting
      def self.included(base)
        base.has_child_handler('rewrite_%{name}')
      end

      # Code to add before and after the node for covering purposes
      def rewrite
      end

      # Default child rewriting rule
      def rewrite_child(child, name = nil)
      end

      # Replaces all the '%{local}' or '%{some_tracker}' in rewriting rules
      def resolve_rewrite(rule, context)
        return if rule == nil
        sources = context.tracker_sources
        format(rule, local: covered_code.local_var, node: '%{node}', **sources)
      end

      # Returns an array of [range, rule], where rule is a string containing '%{node}'
      # Rules must be ordered inner-most first
      def rewriting_rules
        [
          resolve_rewrite(rewrite, self),
          resolve_rewrite(parent.rewrite_child(self), parent),
        ].compact.map { |rule| [expression, rule] }
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
deep-cover-core-1.1.0 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-1.0.0 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.8.1 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.8.0 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.10 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.9 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.8 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.7 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.6 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.5 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.4 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.3 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.2 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.1 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.7.0 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.6.4 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.6.3 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-core-0.6.3.pre lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.6.2 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.6.1 lib/deep_cover/node/mixin/rewriting.rb