{"id":17159637,"url":"https://github.com/schmidt/structured_warnings","last_synced_at":"2025-04-13T13:26:38.651Z","repository":{"id":737239,"uuid":"387497","full_name":"schmidt/structured_warnings","owner":"schmidt","description":"This is an implementation of Daniel Berger's proposal of structured warnings for Ruby.","archived":false,"fork":false,"pushed_at":"2022-10-09T13:59:40.000Z","size":103,"stargazers_count":16,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T04:33:14.445Z","etag":null,"topics":["hacktoberfest","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schmidt.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-11-27T14:20:25.000Z","updated_at":"2022-09-30T09:03:05.000Z","dependencies_parsed_at":"2022-07-07T18:30:17.546Z","dependency_job_id":null,"html_url":"https://github.com/schmidt/structured_warnings","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmidt%2Fstructured_warnings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmidt%2Fstructured_warnings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmidt%2Fstructured_warnings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmidt%2Fstructured_warnings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schmidt","download_url":"https://codeload.github.com/schmidt/structured_warnings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571840,"owners_count":21126522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","ruby"],"created_at":"2024-10-14T22:14:46.467Z","updated_at":"2025-04-13T13:26:38.628Z","avatar_url":"https://github.com/schmidt.png","language":"Ruby","readme":"# StructuredWarnings\n\nThis is an implementation of Daniel Berger's [proposal of structured warnings\nfor Ruby](https://web.archive.org/web/20140328021259/http://www.oreillynet.com/ruby/blog/2008/02/structured_warnings_now.html).\nThey provide dynamic suppression and activation, as well as, an inheritance\nhierarchy to model their relations. This library preserves the old `warn`\nsignature, but additionally allows a `raise`-like use.\n\nFor more information on the usage and benefits of this library have a look at\nthe inspiring article at O'Reilly.\n\n[www.oreillynet.com/ruby/blog/2008/02/structured\\_warnings\\_now.html](https://web.archive.org/web/20140328021259/http://www.oreillynet.com/ruby/blog/2008/02/structured_warnings_now.html)\n(link to web archive - O'Reilly took it down)\n\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'structured_warnings'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install structured_warnings\n\n\n## Compatibility\n\n`structured_warnings` aims to work with all Ruby interpreters. Please file a bug\nfor any incompatibilities.\n\n\nVersions of `structured_warnings` before `v0.3.0` are incompatible with Ruby\n2.4+. Please upgrade accordingly, if you need Ruby 2.4 compatibility. Please\nnote on the otherhand, that many class names changed in an incompatible way\nwith `structured_warnings` `v0.3.0`. This was done to avoid future name clashes.\n\nHere's a table which should ease upgrading.\n\n| v0.2.0 and before            | v0.3.0 and after                                 |\n|------------------------------|--------------------------------------------------|\n| `Warning`                    | `StructuredWarnings::Base`                       |\n| `StandardWarning`            | `StructuredWarnings::StandardWarning`            |\n| `DeprecationWarning`         | `StructuredWarnings::DeprecationWarning`         |\n| `DeprecatedMethodWarning`    | `StructuredWarnings::DeprecatedMethodWarning`    |\n| `DeprecatedSignatureWarning` | `StructuredWarnings::DeprecatedSignatureWarning` |\n\n\n### Test framework support\n\n`structured_warnings` supports both\n[test-unit](https://github.com/test-unit/test-unit/) and\n[minitest/test](https://github.com/seattlerb/minitest/) by adding the\n`assert_warn` and `assert_no_warn` assertions.\n\nPull requests which add support for `RSpec` or `minitest/spec` are very welcome.\n\n\n### Known Issues\n\nIn Ruby versions before 2.4, the library may not extend Ruby's built-in\nwarnings handled by the C-level function `rb_warn`. Therefore warnings like\n\"method redefined\", \"void context\", and \"parenthesis\" may not be manipulated by\n`structured_warnings`.\n\n\n## Usage\n\nTo get you started - here is a short example\n\nIn order to use `structured_warnings` in library code, use the following code.\n\n```ruby\n# in lib/...\nrequire 'structured_warnings'\n\nclass Foo\n  def old_method\n    warn StructuredWarnings::DeprecatedMethodWarning, 'This method is deprecated. Use new_method instead'\n    # Do stuff\n  end\nend\n\n# in test/...\nrequire 'test/unit'\nrequire 'structured_warnings'\n\nclass FooTests \u003c Test::Unit::TestCase\n  def setup\n    @foo = Foo.new\n  end\n\n  def test_old_method_emits_deprecation_warning\n    assert_warn(StructuredWarnings::DeprecatedMethodWarning){ @foo.old_method }\n  end\nend\n```\n\n`StructuredWarnings::DeprecatedMethodWarning` is only one of multiple predefined\nwarning types. You may add your own types by subclassing\n`StructuredWarnings::Base` if you like.\n\nClient code of your library will look as follows:\n\n```ruby\nrequire \"foo\"\n\nfoo = Foo.new\nfoo.old_method # =\u003e will print\n               # ... `old_method' : This method is deprecated. Use new_method instead (StructuredWarnings::DeprecatedMethodWarning)\n```\n\nBut the main difference to the standard warning concept shipped with ruby, is\nthat the client is able to selectively disable certain warnings s/he is aware of\nand not willing to fix.\n\n```ruby\nStructuredWarnings::DeprecatedMethodWarning.disable # Globally disable warnings about deprecated methods!\n\nfoo.old_method # =\u003e will print nothing\n\nStructuredWarnings::DeprecatedMethodWarning.enable # Reenable warnings again.\n```\n\nAnd there is an even more powerful option for your clients, the can selectively\ndisable warnings in a dynamic block scope.\n\n```ruby\n# Don't bug me about deprecated method warnings within this block, I know\n# what I'm doing.\n#\nStructuredWarnings::DeprecatedMethodWarning.disable do\n  foo.old_method\nend\n```\n\nThese settings are scoped to the local thread (and all threads spawned in the\nblock scope) and automatically reset after the block.\n\n\n## Detailed Documentation\n\nHave closer look at the RDoc of `StructuredWarnings::Warning`,\n`StructuredWarnings::Base` and `StructuredWarnings::Base::ClassMethods`.\n\nPart of this library is a set of different warnings:\n\n* `StructuredWarnings::Base`\n  * `StructuredWarnings::BuiltInWarning`\n  * `StructuredWarnings::StandardWarning`\n  * `StructuredWarnings::DeprecationWarning`\n    * `StructuredWarnings::DeprecatedMethodWarning`\n    * `StructuredWarnings::DeprecatedSignatureWarning`\n\nYou are encouraged to use your own subclasses of `StructuredWarnings::Base` to\ngive as much feedback to your users as possible.\n\n\n## Resources\n\n* [Inspiring article](https://web.archive.org/web/20140328021259/http://www.oreillynet.com/ruby/blog/2008/02/structured_warnings_now.html)\n* [Implementation Highlights](http://www.nach-vorne.de/2008/2/22/structured_warnings-highlights)\n* [Project's website](https://github.com/schmidt/structured_warnings/)\n* [API doc](http://rdoc.info/projects/schmidt/structured_warnings)\n* [Build status](https://github.com/schmidt/structured_warnings/actions)\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run\n`rake test` to run the tests. You can also run `bin/console` for an interactive\nprompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To\nrelease a new version, update the version number in `version.rb`, and then run\n`bundle exec rake release`, which will create a git tag for the version, push\ngit commits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\n[github.com/schmidt/structured\\_warnings](https://github.com/schmidt/structured_warnings).\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT\nLicense](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschmidt%2Fstructured_warnings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschmidt%2Fstructured_warnings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschmidt%2Fstructured_warnings/lists"}