Skip to content

Commit

Permalink
Merge pull request #23 from alpaca-tc/support-dry
Browse files Browse the repository at this point in the history
Support dry gem
  • Loading branch information
alpaca-tc authored May 8, 2024
2 parents 4139762 + d1ca6c9 commit 01af420
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/diver_down/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def self.normalize_module_name(obj)
# @return [Module, Class]
def self.resolve_module(obj)
if module?(obj) # Do not call method of this
resolve_singleton_class(obj)
if module_subclass?(obj)
obj.class
else
resolve_singleton_class(obj)
end
else
k = INSTANCE_CLASS_QUERY.bind_call(obj)
resolve_singleton_class(k)
Expand Down Expand Up @@ -62,5 +66,12 @@ def self.class?(obj)
def self.constantize(str)
::ActiveSupport::Inflector.constantize(str)
end

# FIXME: I don't know the best way to determine which class inherits from Module.
# @return [Boolean]
def self.module_subclass?(mod)
mod.ancestors.size == 1 &&
mod.class < Module
end
end
end
2 changes: 1 addition & 1 deletion lib/diver_down/trace/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def build_trace_point

mod = DiverDown::Helper.resolve_module(tp.self)

if mod.nil?
unless mod
call_stack.push
next
end
Expand Down
13 changes: 13 additions & 0 deletions spec/diver_down/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ def self.name
expect(described_class.resolve_module(mod)).to eq(mod)
end

it 'returns class given inherited module' do
class A < ::Module
# @return [nil]
def name
raise 'This method should not be called'
end
end

expect(described_class.resolve_module(A.new)).to eq(A)
ensure
Object.send(:remove_const, :A)
end

it 'returns string given class' do
klass = Class.new do
def self.name
Expand Down

0 comments on commit 01af420

Please sign in to comment.