Sha256: 24fe2a3ba29adfb10a0df9d6158604150e69da8bfd705cca9c22a6802aa82557

Contents?: true

Size: 963 Bytes

Versions: 13

Compression:

Stored size: 963 Bytes

Contents

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

13 entries across 13 versions & 1 rubygems

Version Path
deep-cover-0.1.14 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.13 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.12 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.11 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.10 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.9 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.8 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.7 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.6 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.5 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.4 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.3 lib/deep_cover/node/mixin/rewriting.rb
deep-cover-0.1.2 lib/deep_cover/node/mixin/rewriting.rb