Skip to content

Commit

Permalink
feat(root): introduce ConvenientService.root
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Dec 12, 2023
1 parent 07ce10f commit dc5af36
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions lib/convenient_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,27 @@ def logger
end

##
# Returns Convenient Service root folder. Inspired by `Rails.root`.
# For example, it may return something like: `/Users/user/.asdf/installs/ruby/2.7.0/lib/ruby/gems/2.7.0/gems/convenient_service-0.16.0`.
#
# @api public
#
# @return [Pathname]
#
# @see https://ruby-doc.org/core-2.7.1/Kernel.html#method-i-__dir__
# @see https://api.rubyonrails.org/classes/Rails.html#method-c-root
#
# @internal
# TODO: Specs.
#
def root
@root ||= ::Pathname.new(__dir__)
@root ||= ::Pathname.new(::File.expand_path(::File.join(__dir__, "..")))
end

##
# Returns Convenient Service Examples folder.
# For example, it may return something like: `/Users/user/.asdf/installs/ruby/2.7.0/lib/ruby/gems/2.7.0/gems/convenient_service-0.16.0/lib/convenient_service/examples`.
#
# @api private
#
# @return [Pathname]
Expand All @@ -73,7 +82,7 @@ def root
# TODO: Specs.
#
def examples_root
@examples_root ||= ::Pathname.new(::File.join(root, "examples"))
@examples_root ||= ::Pathname.new(::File.join(root, "lib", "convenient_service", "examples"))
end
end
end
2 changes: 1 addition & 1 deletion lib/convenient_service/support/backtrace_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def initialize(...)
# @return [void]
#
def add_convenient_service_silencer
add_silencer { |line| line.include?(::ConvenientService.root.to_s) && !line.include?(::ConvenientService.examples_root.to_s) }
add_silencer { |line| line.start_with?(::ConvenientService.root.to_s) && !line.start_with?(::ConvenientService.examples_root.to_s) }
end

##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
end

it "does NOT silences Convenient Service examples" do
expect(backtrace_cleaner.clean(["#{ConvenientService.root}/examples/foo.rb"])).to eq(["#{ConvenientService.root}/examples/foo.rb"])
expect(backtrace_cleaner.clean(["#{ConvenientService.examples_root}/foo.rb"])).to eq(["#{ConvenientService.examples_root}/foo.rb"])
end

context "when backtrace is `nil`" do
Expand Down

0 comments on commit dc5af36

Please sign in to comment.