
Several steps were made to achieve mutant working with Ruby 2.4 without warnings and spec failures: * Fix Fixnum deprecation warning * Update RuboCop to 0.47 and fix offenses * Relax version requirements on parser gem * Update diff-lcs to 1.3 * Update rake 11.x -> 12.x * Update reek 4.5 -> 4.6 (to work with parser 2.4) * Update json 2.0 -> 2.1 * Update parallel 1.10 -> 1.11 * Update simplecov 0.12 -> 0.14 * Run regexp_parser integration against v0.4.3 (as we requiring this exact version) * Update warnings.yml with new whitelist * Run CircleCI tests on Ruby 2.3 and 2.4 (Bundler.with_clean_env was causing troubles on new CircleCI 2.0 setup, so it was removed)
92 lines
2.1 KiB
Ruby
92 lines
2.1 KiB
Ruby
module Mutant
|
|
module AST
|
|
|
|
# Helper methods to define named children
|
|
module NamedChildren
|
|
|
|
# Hook called when module gets included
|
|
#
|
|
# @param [Class, Module] host
|
|
#
|
|
# @return [undefined]
|
|
def self.included(host)
|
|
host.class_eval do
|
|
include InstanceMethods
|
|
extend ClassMethods
|
|
end
|
|
end
|
|
|
|
# Methods mixed int ot instance level
|
|
module InstanceMethods
|
|
|
|
private
|
|
|
|
# Mutated nodes children
|
|
#
|
|
# @return [Array<Parser::AST::Node]
|
|
def children
|
|
node.children
|
|
end
|
|
|
|
end # InstanceMethods
|
|
|
|
# Methods mixed in at class level
|
|
module ClassMethods
|
|
|
|
private
|
|
|
|
# Define named child
|
|
#
|
|
# @param [Symbol] name
|
|
# @param [Integer] index
|
|
#
|
|
# @return [undefined]
|
|
def define_named_child(name, index)
|
|
define_private_method(name) do
|
|
children.at(index)
|
|
end
|
|
end
|
|
|
|
# Define remaining children
|
|
#
|
|
# @param [Array<Symbol>] names
|
|
#
|
|
# @return [undefined]
|
|
def define_remaining_children(names)
|
|
define_private_method(:remaining_children_with_index) do
|
|
children.each_with_index.drop(names.length)
|
|
end
|
|
|
|
define_private_method(:remaining_children_indices) do
|
|
children.each_index.drop(names.length)
|
|
end
|
|
|
|
define_private_method(:remaining_children) do
|
|
children.drop(names.length)
|
|
end
|
|
end
|
|
|
|
# Create name helpers
|
|
#
|
|
# @return [undefined]
|
|
def children(*names)
|
|
names.each_with_index do |name, index|
|
|
define_named_child(name, index)
|
|
end
|
|
define_remaining_children(names)
|
|
end
|
|
|
|
# Define private method
|
|
#
|
|
# @param [Symbol] name
|
|
#
|
|
# @return [undefined]
|
|
def define_private_method(name, &block)
|
|
define_method(name, &block)
|
|
private(name)
|
|
end
|
|
|
|
end # ClassMethods
|
|
end # NamedChildren
|
|
end # AST
|
|
end # Mutant
|