{"id":15101467,"url":"https://github.com/viralpraxis/purist","last_synced_at":"2026-02-02T07:07:23.562Z","repository":{"id":225898766,"uuid":"767169732","full_name":"viralpraxis/purist","owner":"viralpraxis","description":"Automatic runtime impure ruby methods invocation detection","archived":false,"fork":false,"pushed_at":"2024-03-10T14:23:15.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-11T22:03:17.803Z","etag":null,"topics":["functional-programming","purity","rspec","ruby","testing"],"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/viralpraxis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-04T20:31:32.000Z","updated_at":"2024-03-10T13:15:15.000Z","dependencies_parsed_at":"2024-03-10T13:26:01.436Z","dependency_job_id":"bbee816e-7204-45b9-a391-3b193cfe5f04","html_url":"https://github.com/viralpraxis/purist","commit_stats":{"total_commits":2,"total_committers":2,"mean_commits":1.0,"dds":0.5,"last_synced_commit":"9ee2f29e41b1d7692da4445b98e679b49a36cafd"},"previous_names":["viralpraxis/iotrack"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/viralpraxis/purist","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viralpraxis%2Fpurist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viralpraxis%2Fpurist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viralpraxis%2Fpurist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viralpraxis%2Fpurist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viralpraxis","download_url":"https://codeload.github.com/viralpraxis/purist/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viralpraxis%2Fpurist/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262891216,"owners_count":23380583,"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":["functional-programming","purity","rspec","ruby","testing"],"created_at":"2024-09-25T18:23:44.912Z","updated_at":"2026-02-02T07:07:23.556Z","avatar_url":"https://github.com/viralpraxis.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Purist\n\nPurist is a tool designed to help detecting impure ruby code in runtime.\n\nRuby's stdlib and corelibs include a bunch of impure methods, including\n\n1. randomization: `Kernel.rand`, `Random.rand`, `SecureRandom.hex` and so on\n\n2. IO-related methods like `Kernel.readline` or `IO.popen`\n\n3. specialized side-effects like `Kernel.fork` or `Kernel.syscall`\n\nPurist hooks into ruby's `tracepoint` API to detect any invocation of these methods.\nYou can see the full list of target methods in `configuration.rb` source file.\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n    $ bundle add purist\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n    $ gem install purist\n\n## Usage\n\nTo check if your code is pure, simply pass it into `Purist.trace` method:\n\n```ruby\nPurist.trace { 3 * 3 } # 9\n```\n\nIf provided block is impure, an exception will be raised:\n\n```ruby\nirb(main):001\u003e Purist.trace { p \"I'm impure\" }\ngems/purist/lib/purist/handler.rb:23:in `call': {:path=\u003e\"(irb)\", :lineno=\u003e1, :module_name=\u003eKernel, :method_name=\u003e:p} (Purist::Errors::PurityViolationError)\n```\n\nYou can retrieve exception details like this:\n\n```ruby\nexception = Purist.trace { p 1 } rescue $!\n\np exception.trace_point\n\n{\n  :path =\u003e \".../zeitwerk-2.6.13/lib/zeitwerk/kernel.rb\",\n  :lineno =\u003e 23,\n  :module_name =\u003e Kernel,\n  :method_name =\u003e :require,\n  :backtrace =\u003e [...]\n}\n```\n\n### RSpec integration\n\nPurist comes with built-in `RSpec` integration. To enable it, add `require \"purist/integrations/rspec\"` to your\n`spec_helper.rb` and manually include `Purist::Integrations::RSpec::Matchers`:\n\n```ruby\nrequire \"purist/integrations/rspec\"\n\n...\n\nRSpec.configure do |config|\n  ...\n  config.include Purist::Integrations::RSpec::Matchers\n  ...\nend\n```\n\nAnd not `be_pure` and `be_impure` matchers are available:\n\n```ruby\nexpect { Module.new }.to be_pure\nexpect { User.where(name: :john) }.to be_impure\n```\n\n### Caveats\n\n1. Passing `Purist.trace` check does not mean your function is totally pure, for instance\n\n```ruby\ndef foo(n)\n  if n \u003e 0 # pure branch\n    n.succ\n  else # impure branch\n    p n\n  end\nend\n\nPurist.trace { foo(3) } # 4\n```\n\n2. Ruby stdlib/corelib is quite big, I'm pretty sure some impure functions are missing from the list.\n\n3. Obviously, Purist is unable to detect anything within 3rd-party C extensions.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/viralpraxis/purist. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/viralpraxis/purist/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Purist project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/viralpraxis/purist/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviralpraxis%2Fpurist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviralpraxis%2Fpurist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviralpraxis%2Fpurist/lists"}