diff --git a/config/flay.yml b/config/flay.yml index 57f9d0d1..06b115ff 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 1160 +total_score: 1162 diff --git a/config/flog.yml b/config/flog.yml index 2f43979a..2c02e555 100644 --- a/config/flog.yml +++ b/config/flog.yml @@ -1,2 +1,2 @@ --- -threshold: 29.3 +threshold: 27.7 diff --git a/lib/mutant/ast/meta/const.rb b/lib/mutant/ast/meta/const.rb index f19ff974..2f3b01d6 100644 --- a/lib/mutant/ast/meta/const.rb +++ b/lib/mutant/ast/meta/const.rb @@ -9,6 +9,8 @@ module Mutant children :base, :name + public :base, :name + # Test if AST node is possibly a top level constant # # @return [Boolean] diff --git a/lib/mutant/ast/meta/optarg.rb b/lib/mutant/ast/meta/optarg.rb index 0b1a8558..a2fcfe9f 100644 --- a/lib/mutant/ast/meta/optarg.rb +++ b/lib/mutant/ast/meta/optarg.rb @@ -11,6 +11,8 @@ module Mutant children :name, :default_value + public :name, :default_value + # Test if optarg definition intends to be used # # @return [Boolean] diff --git a/lib/mutant/ast/meta/resbody.rb b/lib/mutant/ast/meta/resbody.rb index dbefec10..fe34790d 100644 --- a/lib/mutant/ast/meta/resbody.rb +++ b/lib/mutant/ast/meta/resbody.rb @@ -8,6 +8,8 @@ module Mutant include NamedChildren, Concord.new(:node) children :captures, :assignment, :body + + public :captures, :assignment, :body end # Resbody end # Meta diff --git a/lib/mutant/ast/meta/restarg.rb b/lib/mutant/ast/meta/restarg.rb index 3e1165c4..43705868 100644 --- a/lib/mutant/ast/meta/restarg.rb +++ b/lib/mutant/ast/meta/restarg.rb @@ -8,6 +8,8 @@ module Mutant include NamedChildren, Concord.new(:node) children :name + + public :name end # Restarg end # Meta diff --git a/lib/mutant/ast/meta/send.rb b/lib/mutant/ast/meta/send.rb index 6f1e9d4e..9689f58e 100644 --- a/lib/mutant/ast/meta/send.rb +++ b/lib/mutant/ast/meta/send.rb @@ -9,6 +9,8 @@ module Mutant children :receiver, :selector + public :receiver, :selector + INDEX_ASSIGNMENT_SELECTOR = :[]= ATTRIBUTE_ASSIGNMENT_SELECTOR_SUFFIX = '='.freeze @@ -16,6 +18,7 @@ module Mutant # # @return [Enumerable] alias_method :arguments, :remaining_children + public :arguments # Test if AST node is a valid assignment target # diff --git a/lib/mutant/ast/meta/symbol.rb b/lib/mutant/ast/meta/symbol.rb index daa87b8a..941738ed 100644 --- a/lib/mutant/ast/meta/symbol.rb +++ b/lib/mutant/ast/meta/symbol.rb @@ -9,6 +9,8 @@ module Mutant children :name + public :name + end # Symbol end # Meta end # AST diff --git a/lib/mutant/ast/named_children.rb b/lib/mutant/ast/named_children.rb index 8fedf767..1657da7e 100644 --- a/lib/mutant/ast/named_children.rb +++ b/lib/mutant/ast/named_children.rb @@ -42,7 +42,7 @@ module Mutant # # @return [undefined] def define_named_child(name, index) - define_method(name) do + define_private_method(name) do children.at(index) end end @@ -53,15 +53,15 @@ module Mutant # # @return [undefined] def define_remaining_children(names) - define_method(:remaining_children_with_index) do + define_private_method(:remaining_children_with_index) do children.each_with_index.drop(names.length) end - define_method(:remaining_children_indices) do + define_private_method(:remaining_children_indices) do children.each_index.drop(names.length) end - define_method(:remaining_children) do + define_private_method(:remaining_children) do children.drop(names.length) end end @@ -76,6 +76,14 @@ module Mutant define_remaining_children(names) end + # Define private method + # + # @param [Symbol] name + def define_private_method(name, &block) + define_method(name, &block) + private(name) + end + end # ClassMethods end # NamedChildren end # AST diff --git a/spec/unit/mutant/ast/named_children_spec.rb b/spec/unit/mutant/ast/named_children_spec.rb index e670d959..512a40e6 100644 --- a/spec/unit/mutant/ast/named_children_spec.rb +++ b/spec/unit/mutant/ast/named_children_spec.rb @@ -8,6 +8,14 @@ RSpec.describe Mutant::AST::NamedChildren do end end + def publish + klass.class_eval do + public :foo, :bar + + public :remaining_children, :remaining_children_indices, :remaining_children_with_index + end + end + let(:instance) { klass.new(node) } let(:node_foo) { s(:foo) } @@ -17,26 +25,42 @@ RSpec.describe Mutant::AST::NamedChildren do let(:node) { s(:node, node_foo, node_bar, node_baz) } describe 'generated methods' do + specify 'are private by default' do + %i[ + foo + bar + remaining_children + remaining_children_indices + remaining_children_with_index + ].each do |name| + expect(klass.private_instance_methods.include?(name)).to be(true) + end + end + describe '#remaining_children' do it 'returns remaining unnamed children' do + publish expect(instance.remaining_children).to eql([node_baz]) end end describe '#remaining_children_indices' do it 'returns remaining unnamed children indices' do + publish expect(instance.remaining_children_indices).to eql([2]) end end describe '#remaining_children_with_index' do it 'returns remaining unnamed children indices' do + publish expect(instance.remaining_children_with_index).to eql([[node_baz, 2]]) end end describe '#foo' do it 'returns named child foo' do + publish expect(instance.foo).to be(node_foo) end end @@ -44,6 +68,7 @@ RSpec.describe Mutant::AST::NamedChildren do describe '#bar' do context 'when node is present' do it 'returns named child bar' do + publish expect(instance.bar).to be(node_bar) end end @@ -52,6 +77,7 @@ RSpec.describe Mutant::AST::NamedChildren do let(:node) { s(:node, node_foo) } it 'returns nil' do + publish expect(instance.bar).to be(nil) end end