Sha256: 79fcce9c6169ff29f1c3a898d16af5b03e9ff0cf09e5909cc17d74a8135a2967

Contents?: true

Size: 1.13 KB

Versions: 59

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Mutant
  class Mutator
    class Node
      # Mutator for rescue nodes
      class Rescue < self

        handle :rescue

        children :body

        define_named_child(:else_body, -1)

        RESCUE_INDICES = (1..-2).freeze

      private

        def dispatch
          mutate_body
          mutate_rescue_bodies
          mutate_else_body
        end

        def mutate_rescue_bodies
          children_indices(RESCUE_INDICES).each do |index|
            mutate_child(index)
            resbody_body = AST::Meta::Resbody.new(children.fetch(index)).body
            emit_concat(resbody_body) if resbody_body
          end
        end

        def emit_concat(child)
          if body
            emit(s(:begin, body, child))
          else
            emit(child)
          end
        end

        def mutate_body
          return unless body
          emit_body_mutations
          emit(body)
        end

        def mutate_else_body
          return unless else_body
          emit_else_body_mutations
          emit_concat(else_body)
        end

      end # Rescue
    end # Node
  end # Mutator
end # Mutant

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
mutant-0.11.18 lib/mutant/mutator/node/rescue.rb
mutant-0.11.17 lib/mutant/mutator/node/rescue.rb
mutant-0.11.16 lib/mutant/mutator/node/rescue.rb
mutant-0.11.15 lib/mutant/mutator/node/rescue.rb
mutant-0.11.14 lib/mutant/mutator/node/rescue.rb
mutant-0.11.13 lib/mutant/mutator/node/rescue.rb
mutant-0.11.12 lib/mutant/mutator/node/rescue.rb
mutant-0.11.11 lib/mutant/mutator/node/rescue.rb
mutant-0.11.10 lib/mutant/mutator/node/rescue.rb
mutant-0.11.9 lib/mutant/mutator/node/rescue.rb
mutant-0.11.8 lib/mutant/mutator/node/rescue.rb
mutant-0.11.7 lib/mutant/mutator/node/rescue.rb
mutant-0.11.6 lib/mutant/mutator/node/rescue.rb
mutant-0.11.5 lib/mutant/mutator/node/rescue.rb
mutant-0.11.4 lib/mutant/mutator/node/rescue.rb
mutant-0.11.3 lib/mutant/mutator/node/rescue.rb
mutant-0.11.2 lib/mutant/mutator/node/rescue.rb
mutant-0.11.1 lib/mutant/mutator/node/rescue.rb
mutant-0.11.0 lib/mutant/mutator/node/rescue.rb
mutant-0.10.35 lib/mutant/mutator/node/rescue.rb