Skip to content

Commit

Permalink
Dynamically load files
Browse files Browse the repository at this point in the history
  • Loading branch information
that-jill committed Feb 1, 2024
1 parent b588b73 commit 3b492d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/dep_shield/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Introducing DepShield, your go-to Ruby gem for proactive deprecation management

With DepShield, developers can stay ahead of the curve by receiving real-time alerts about deprecated code, ensuring a smoother transition to future updates. Tailor your development and demo environments to raise alarms, preventing the introduction of new deprecations. In addition, DepShield offers the flexibility to configure self-reporting mechanisms, allowing seamless issue notifications, configurable by environment Say goodbye to unexpected deprecation surprises and embrace a more streamlined and informed coding experience with DepShield!

## Setup

After installing DepShield, load any todo lists in your application with:

`DepShield.todos.load("path-to-deprecation_todos.yml")`

## Usage

`DepShield#raise_or_capture!` is used to mark methods as deprecated. When called, it will intelligently warn or raise exceptions to alert developers to the deprecated activity. The method expects two arguments, a `name` (ie, the name of the deprecation you're introducing), and a `message` (usually information about what is deprecated and how to fix it). Marking something as deprecated is pretty simple:
Expand All @@ -22,10 +28,21 @@ This is used in conjuction with NitroConfig to define how different environment
Option A: the result of this is a logged warning every time the method is called.
Option B: this will raise and notify our error catcher (Sentry).

If a developer needs to bypass this/defer fixing the deprecation to a future date, the call can be "grandfathered" by adding this information to the allowlist in `.deprecation_todo.yml` in the application/component that hosts the deprecated reference. For example, if you have a method in the `authors` component that references `Books.category`:
If a developer needs to bypass this/defer fixing the deprecation to a future date, the call can be "grandfathered" by adding this information to the allowlist in a `.deprecation_todo.yml` file in the application/component that hosts the deprecated reference. For example, if you have a method in the `authors` component that references `Books.category`:

```ruby
# components/authors/lib/book_information.rb

book_category = Books.category
```

You could disable this with:

```yml
# components/authors/.deprecation_todo.yml

books_default_category:
- components/authors/lib/book_information.rb
```
More details and another example can be found [here](https://github.com/powerhome/power-tools/blob/main/packages/dep_shield/spec/internal/config/.deprecation_todo.yml)
3 changes: 3 additions & 0 deletions packages/dep_shield/spec/dep_shield/deprecation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
context "#raise_or_capture!" do
describe "configured to capture_deprecation" do
before do
DepShield.todos.load(Rails.root.join("config", ".deprecation_todo.yml"))
DepShield.todos.load(Rails.root.join("config", ".empty_deprecation_todo.yml"))

allow(NitroConfig).to receive(:get).with("nitro_errors/capture_deprecation").and_return true
end

Expand Down

0 comments on commit 3b492d1

Please sign in to comment.