danmayer / coverband

Ruby production code coverage collection and reporting (line of code usage)
https://github.com/danmayer/coverband
MIT License
2.46k stars 157 forks source link

Override default Configuration root with an env var #532

Closed captainkevron closed 4 months ago

captainkevron commented 4 months ago

First off, thank you for maintaining this project. It has been extremely valuable for our organization in removing dead code from legacy applications.

We are currently integrating coverband with a Sinatra app and ran into a blocker. Due to a pile of shell scripts and symbolic links in our infrastructure, we need to be able to set the configuration root via an environment variable. This PR will set the configuration root to the value of the environment variable "COVERBAND_ROOT" and fall back to the previous behavior when it is not set.

For some additional context, our applications are deployed using conventions similar to Capistrano.

The live code is referenced via a symbolic link current pointing to the directory where the code actually lives.

danmayer commented 4 months ago

I believe this has come up in the past and there are some other ways you can handle this... I am not opposed to pulling this in if you really need it but can you first try using some of the other methods to set the root via existing config options.

inside your config, I think you can try a couple things...

# config/coverband.rb NOT in the initializers
Coverband.configure do |config|
  config.root = "/whatever/path"

  # alternatively there was a way to handle multiple / dynamic roots via root_paths array which setups up searching multiple paths
  config.root_paths = ["running_directory/path", "dynamic_path/pattern", "red/blue/paths"]
end
danmayer commented 4 months ago

thanks for the feedback and PR and let me know if any of these options work for you.

captainkevron commented 4 months ago

@danmayer Thanks for the suggestion. Setting config.root worked fine. That solution was staring me right in the face and I totally missed it. Appreciate the help.

danmayer commented 4 months ago

excellent glad that worked for you, I haven't had a need for the changing deploy directory for a long time so I am glad it is still working as expected. Thanks