Event driven Rails application with Rails Event Store

https://railseventstore.org/docs/start/

Just use provided application template and run:
rails new -m https://railseventstore.org/new YOUR-APP-NAME
rails events event-sourcing event-driven rails-event-store 1,068 2


dev
dev

May 25, 2020

Copy and paste this code into your terminal

DISCLAIMER: You should always review templates before running them. By running the template, you are agreeing to the terms of use.

The contents of this script as show. Any updates will be reflected in the below code and the snippet.

gem 'rails_event_store', '~> 1.0.0'

after_bundle do
  initializer 'rails_event_store.rb', <<~CODE
    require 'rails_event_store'
    require 'aggregate_root'
    require 'arkency/command_bus'

    Rails.configuration.to_prepare do
      Rails.configuration.event_store = RailsEventStore::Client.new
      Rails.configuration.command_bus = Arkency::CommandBus.new

      AggregateRoot.configure do |config|
        config.default_event_store = Rails.configuration.event_store
      end

      # Subscribe event handlers below
      # Rails.configuration.event_store.tap do |store|
      #   store.subscribe(InvoiceReadModel.new, to: [InvoicePrinted])
      #   store.subscribe(->(event) { SendOrderConfirmation.new.call(event) }, to: [OrderSubmitted])
      #   store.subscribe_to_all_events(->(event) { Rails.logger.info(event.type) })
      # end

      # Register command handlers below
      # Rails.configuration.command_bus.tap do |bus|
      #   bus.register(PrintInvoice, Invoicing::OnPrint.new)
      #   bus.register(SubmitOrder,  ->(cmd) { Ordering::OnSubmitOrder.new.call(cmd) })
      # end
    end
  CODE

  generate 'rails_event_store_active_record:migration'
  rails_command 'db:migrate'
  route "mount RailsEventStore::Browser => '/res' if Rails.env.development?"
end

A place where you can thank the author, post problems, give constructive feedback, etc. Be nice!