{"id":24716708,"url":"https://github.com/baylorrae/event_sourcery-rails","last_synced_at":"2026-05-06T22:31:27.925Z","repository":{"id":56845000,"uuid":"169902364","full_name":"BaylorRae/event_sourcery-rails","owner":"BaylorRae","description":"Combining two great powers for data and web.","archived":false,"fork":false,"pushed_at":"2019-02-10T18:18:00.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T11:39:49.161Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/BaylorRae.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-09T19:02:40.000Z","updated_at":"2019-02-10T18:18:02.000Z","dependencies_parsed_at":"2022-09-09T21:10:54.521Z","dependency_job_id":null,"html_url":"https://github.com/BaylorRae/event_sourcery-rails","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaylorRae%2Fevent_sourcery-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaylorRae%2Fevent_sourcery-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaylorRae%2Fevent_sourcery-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaylorRae%2Fevent_sourcery-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BaylorRae","download_url":"https://codeload.github.com/BaylorRae/event_sourcery-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244932908,"owners_count":20534250,"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":"2025-01-27T09:13:59.903Z","updated_at":"2026-05-06T22:31:27.888Z","avatar_url":"https://github.com/BaylorRae.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EventSourcery::Rails\n[![Build Status](https://travis-ci.org/BaylorRae/event_sourcery-rails.svg?branch=master)](https://travis-ci.org/BaylorRae/event_sourcery-rails)\n\nI wanted to add [Event Sourcing][event_sourcing_fowler] to my Rails application\nand after using several libraries/framework settled on EventSourcery from\nEnvato. After creating a demo application based on their todo example with Rails\nI realized the installation steps are pretty simple. With this gem it can be\ninstalled and configured with a single rake task!\n\nIn addition to automating the install, I also wanted to incorporate the DSL from\nSequent and RailsEventStore for commands and command handlers. I like the\ncommand handler itself wrapping single responsibility around an aggregate with\nthe `on` command binding. I also wanted to remove the boilerplate for\ninstantiating and validating commands since we can load\n`ActiveModel::Validations` for free.\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Commands](#commands)\n  - [Command Handlers](#command-handlers)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\nAdd the following line to your Gemfile.\n\n```ruby\ngem 'event_sourcery'\ngem 'event_sourcery-postgres'\ngem 'event_sourcery-rails'\n```\n\nThen run `bundle install`\n\nNext, your need to run the generator:\n\n```bash\n$ rails generate event_sourcery_rails:install\n```\n\nAt this point you will have an initializer to configure EventSourcery and the\nfollowing Rake tasks.\n\n```bash\n$ rails event_sourcery:db:migrate # create the event sourcery schema\n$ rails event_sourcery:processors:setup # create projector schemas\n$ rails event_sourcery:processors:reset # drop and recreate projector schemas and data\n$ rails event_sourcery:processors:run # start event stream processors\n```\n\nTypically you'll have the following in your Procfile.\n\n```yaml\nweb: rails server\nprocessors: rails event_sourcery:processors:run\n```\n\n## Usage\n\n### Commands\n\nEventSourcery::Rails adds an optional base class for commands to enforce\ninstantiating commands with an `aggregate_id` and required parameters as keyword\narguments. Defined attributes are available with an `attr_reader`.\n\nIncludes [`ActiveModel::Validations`][active_model_validations] for validating\nattributes.\n\n```ruby\nclass AddUser \u003c EventSourcery::Rails::Command\n  attributes :name, :email\n  validates_presence_of :name, :email\nend\n\nAddUser.new # =\u003e raises ArgumentError.new(\"missing keywords: aggregate_id, name, email\")\n\ncommand = AddUser.new(aggregate_id: 'aggregate-id',\n                      name: 'name',\n                      email: 'email')\ncommand.aggregate_id # =\u003e \"aggregate-id\"\ncommand.name # =\u003e \"name\"\ncommand.email # =\u003e \"email\"\n\ncommand.valid? # =\u003e true\n```\n\n### Command Handlers\n\nYou can also optionally include `EventSourcery::Rails::CommandHandler` to use\nuse a callback DSL for binding commands. This DSL allows your application code\nto use all command handlers with `#call`.\n\n**Todo**\n\n- [ ] Consider switching to a base class with common initializer and\n    `with_aggregate`\n- [ ] Introduce API for invoking all known command handlers with an array of\n    commands.\n\n```ruby\nclass UserCommandHandler\n  include EventSourcery::Rails::CommandHandler\n\n  attr_reader :repository\n\n  def initialize(repository: EventSourceryRails.repository)\n    @repository = repository\n  end\n\n  on AddUser do |command|\n    aggregate = repository.load(UserAggregate, aggregate_id)\n    aggregate.add(name: command.name,\n                  email: command.email)\n    repository.save(aggregate)\n  end\n\n  on UpdateUserEmail do |command|\n    aggregate = repository.load(UserAggregate, aggregate_id)\n    aggregate.update_email(email: command.email)\n    repository.save(aggregate)\n  end\nend\n```\n\n## Contributing\nPlease submit issues and pull requests for bugs, features or ideas.\n\n## License\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n[event_sourcing_fowler]: https://martinfowler.com/eaaDev/EventSourcing.html\n[active_model_validations]: https://api.rubyonrails.org/classes/ActiveModel/Validations.html#module-ActiveModel::Validations-label-Active+Model+Validations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaylorrae%2Fevent_sourcery-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaylorrae%2Fevent_sourcery-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaylorrae%2Fevent_sourcery-rails/lists"}