{"id":15405621,"url":"https://github.com/krisleech/ma","last_synced_at":"2025-10-08T19:09:03.009Z","repository":{"id":66255565,"uuid":"216228964","full_name":"krisleech/ma","owner":"krisleech","description":"Event Driven Ruby [MIRROR]","archived":false,"fork":false,"pushed_at":"2019-11-09T13:49:53.000Z","size":37,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-17T04:44:46.161Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://gitlab.com/kris.leech/ma","language":"Ruby","has_issues":false,"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/krisleech.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":"2019-10-19T15:36:25.000Z","updated_at":"2021-01-19T22:14:53.000Z","dependencies_parsed_at":"2023-02-20T18:45:13.954Z","dependency_job_id":null,"html_url":"https://github.com/krisleech/ma","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"ce0810ed86dd9fa5fa275903ddd246898770bd45"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krisleech","download_url":"https://codeload.github.com/krisleech/ma/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245359248,"owners_count":20602322,"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":[],"created_at":"2024-10-01T16:17:33.180Z","updated_at":"2025-10-08T19:08:57.960Z","avatar_url":"https://github.com/krisleech.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ma 間\n\n**Events as first class citizens**\n\n\u003e Ma (間) is a Japanese word, it is between spoken words and musical notes.\n\u003e The essence of minimalism, a gap, pause or space.\n\n* An alternative to callbacks and observers\n* Connect objects based on context without permanence\n* Handle events synchronously or asynchronously\n* Loosely couple objects with events\n* A micro library, can be grokked in a day\n\n## Usage\n\n```ruby\nclass MyEvent \u003c Ma::Event\nend\n\nclass MyPublisher\n  include Ma.publisher\n\n  def call\n    # ...\n    broadcast(MyEvent.new(user: user))\n  end\nend\n\nclass MyListener\n  include Ma.subscriber\n\n  on(MyEvent) do |event|\n    # ...\n  end\nend\n\npublisher = MyPublisher.new\npublisher.subscribe(MyListener.new)\npublisher.call\n```\n\n#### Handling Events Asynchronously\n\nMa is build on top of [WisperNext](https://gitlab.com/kris.leech/wisper_next)\nand so takes advantage it's asynchronous adapters.\n\n[Configure an adapter](https://gitlab.com/kris.leech/wisper_next#handling-events-asynchronously) and then pass `:async` as such:\n\n```ruby\nclass MyListener\n  include Ma.subscriber(:async)\nend\n```\n\n### Events\n\nAn event can be any object which must:\n\n* be initialized with a `Hash` of attributes\n* responds to `#to_h` returning a `Hash` of attributes\n\nWe provide a simple event object, `Ma::Event`, but would recommend using\nsomething like [dry-struct](https://dry-rb.org/gems/dry-struct/1.0/) to define an\nevent explicitly.\n\nA useful constraint, when using dry-struct, if you are using asynchronous listeners, is that\nit only supports primative types like `String`, `Integer`, `Hash` and\n`Array`, which are easily serialized for transport over the wire to a background\nworker.\n\n#### Enhancing Events\n\nYou can add additional information to the payload by overriding the\n`#initialize` method:\n\n```ruby\nclass MyEvent \u003c Ma::Event\n  def initialize(attrs)\n    super({ timestamp: Time.now.to_i }.merge(attrs))\n  end\nend\n```\n\n## Installation\n\n```ruby\ngem 'ma'\n```\n\n## Security\n\n* gem releases are [signed](https://gitlab.com/kris.leech/ma/blob/master/keys/gem-public_cert.pem)\n* commits are GPG [signed](https://gitlab.com/kris.leech/ma/blob/master/keys/kris.leech.gpg.public)\n\n## Development\n\n### Specs\n\nRun the specs:\n\n```\nrspec\n```\n\nRuns the specs on file change:\n\n```\nls ./**/*.rb | entr -c rspec\n```\n\n## Contributing\n\nBug reports are welcome on Gitlab at https://gitlab.com/kris.leech/ma.\n\nWe are unlikely to accept new feature requests, but please open an issue if you\nfeel you have something completing and would be prepared to provide a pull\nrequest.\n\nThis 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## 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 Ma project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/kris.leech/ma/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisleech%2Fma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrisleech%2Fma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisleech%2Fma/lists"}