{"id":23249540,"url":"https://github.com/wizardone/shouter","last_synced_at":"2025-06-22T18:09:24.249Z","repository":{"id":56895438,"uuid":"72430714","full_name":"wizardone/shouter","owner":"wizardone","description":"Ruby implementation for a simple publish/subscription based system with callbacks","archived":false,"fork":false,"pushed_at":"2017-09-23T06:21:40.000Z","size":60,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-09T12:22:38.461Z","etag":null,"topics":["callbacks","events","listeners","ruby","singleton","store","subscription"],"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/wizardone.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2016-10-31T11:36:23.000Z","updated_at":"2017-09-19T09:33:53.000Z","dependencies_parsed_at":"2022-08-20T17:10:23.147Z","dependency_job_id":null,"html_url":"https://github.com/wizardone/shouter","commit_stats":null,"previous_names":["wizardone/bouncer"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/wizardone/shouter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fshouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fshouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fshouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fshouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wizardone","download_url":"https://codeload.github.com/wizardone/shouter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fshouter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261338998,"owners_count":23143900,"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":["callbacks","events","listeners","ruby","singleton","store","subscription"],"created_at":"2024-12-19T08:19:51.080Z","updated_at":"2025-06-22T18:09:19.230Z","avatar_url":"https://github.com/wizardone.png","language":"Ruby","readme":"# Shouter\n[![Build Status](https://travis-ci.org/wizardone/shouter.svg?branch=master)](https://travis-ci.org/wizardone/shouter)\n[![codecov](https://codecov.io/gh/wizardone/shouter/branch/master/graph/badge.svg)](https://codecov.io/gh/wizardone/shouter)\n\n`Shouter` is a very simple and lightweight publish/subscription DSL for\nRuby applications.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'shouter'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install shouter\n\n## Usage\n```ruby\nclass A\n  extend Shouter\n  subscribe(Listener.new, for: :my_scope)\nend\n\nclass Listener\n  def on_change\n    \"I`m changed\"\n  end\nend\n\nA.publish(:my_scope, :on_change)\n=\u003e \"I`m changed\"\n```\nSince version `0.1.3` if you want asyncronous execution, using separate threads you can supply\nthe `async` option. By default it is set to `false`\n```ruby\nclass A\n  extend Shouter\n  subscribe(Listener.new, for: :my_async_scope, async: true)\nend\n```\nNow whenever you `publish` and event it will be run in a separate\nthread. If a thread for the execution is already present another one\nwill not be created. If you have supplied a callback option it will be\nexecuted in the thread of execution of the listener.\n\nYou can subscribe multiple objects:\n```ruby\nclass A\n  extend Shouter\n  subscribe(Listener.new, Listener1.new, Listener2.new, for: :my_scope)\nend\n```\n\nYou can subscribe an object for single execution, after that the object\nwill be removed from the listener store\n```ruby\nclass A\n  extend Shouter\n  subscribe(Listener.new, for: :my_scope, single: true)\nend\n\nA.publish(:my_scope, :on_change)\n=\u003e \"I`m changed\"\n\nA.publish(:my_scope, :on_change)\n=\u003e nil\n```\nAll the arguments are passed to the method as well:\n```ruby\nA.publish(:my_scope, :on_change_with_arguments, 'argument_1', 'argument_2')\n```\n\nYou can also pass a block to the publish method, which will serve as a\nsuccessful callback, meaning it will only get executed after the event\nhas been triggered\n```ruby\nA.publish(:my_scope, :on_change) do\n  puts \"I am callback\"\nend\n```\n\nTo unsubscribe single or multiple objects you can call the `unsubscribe` method\n```ruby\nA.unsubscribe(Listener1, Listener2)\n```\n\nSince version `1.0.1`:\n\nAlternatively you can pass the callback option when subscribing.\nIt accepts a callable object:\n```ruby\nsubscribe(Listener.new, for: :my_scope, callback: -\u003e() { perform_async })\n```\n\nYou can now add a `guard` clause which will stop the execution of events\nunless it returns `true`. Guard clauses accept callable objects\n```ruby\nsubscribe(Listener.new, for: :my_scope, guard: Proc.new { some_listener.respond_to?(:my_method) })\n```\n\n\nThe `clear` method removes all listeners from the store.\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 tags, 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/wizardone/shouter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwizardone%2Fshouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwizardone%2Fshouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwizardone%2Fshouter/lists"}