Sha256: 764aca15fe78fa0afee4ea9df3c4e5bece4c3ee99d0307b333d2309e22ca2e17

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require 'event_sourcery'
require 'event_sourcery/postgres'

Dir.glob(__dir__ + '/../app/events/*.rb').each { |f| require f }
Dir.glob(__dir__ + '/../app/reactors/*.rb').each { |f| require f }
Dir.glob(__dir__ + '/../app/projections/**/projector.rb').each { |f| require f }

module <%= project_class_name %>
  class Config
    attr_accessor :database_url
  end

  def self.config
    @config ||= Config.new
  end

  def self.configure
    yield config
  end

  def self.environment
    ENV.fetch('RACK_ENV', 'development')
  end

  def self.event_store
    EventSourcery::Postgres.config.event_store
  end

  def self.event_source
    EventSourcery::Postgres.config.event_store
  end

  def self.tracker
    EventSourcery::Postgres.config.event_tracker
  end

  def self.event_sink
    EventSourcery::Postgres.config.event_sink
  end

  def self.projections_database
    EventSourcery::Postgres.config.projections_database
  end

  def self.repository
    @repository ||= EventSourcery::Repository.new(
      event_source: event_source,
      event_sink: event_sink
    )
  end
end

<%= project_class_name %>.configure do |config|
  config.database_url = ENV['DATABASE_URL'] || "postgres://127.0.0.1:5432/<%= project_name.underscore %>_#{<%= project_class_name %>.environment}"
end

EventSourcery::Postgres.configure do |config|
  database = Sequel.connect(<%= project_class_name %>.config.database_url)

  # NOTE: Often we choose to split our events and projections into separate
  # databases. For the purposes of this example we'll use one.
  config.event_store_database = database
  config.projections_database = database
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
event_sourcery_generators-0.2.0 lib/event_sourcery_generators/generators/templates/project/environment.rb.tt