Skip to content

RubyEventStore configuration - a new way to handle upcoming features #1908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ruby_event_store/lib/ruby_event_store.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require_relative "ruby_event_store/configuration"
require_relative "ruby_event_store/dispatcher"
require_relative "ruby_event_store/subscriptions"
require_relative "ruby_event_store/broker"
Expand Down
26 changes: 26 additions & 0 deletions ruby_event_store/lib/ruby_event_store/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module RubyEventStore
class Configuration
def initialize
load_defaults(VERSION)
end

attr_reader :loaded_defaults
attr_accessor :test

def load_defaults(version)
self.test = "2.17.0" <= version ? "new_value" : "current_value"
@loaded_defaults = version
self
end
end

class << self
def configuration
@configuration ||= Configuration.new
end

def configure
yield(configuration)
end
end
end
23 changes: 23 additions & 0 deletions ruby_event_store/spec/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "spec_helper"
require "ruby_event_store/configuration"

module RubyEventStore
::RSpec.describe Configuration do
specify { expect(RubyEventStore::Configuration.new.load_defaults("2.17.0").loaded_defaults).to eq("2.17.0") }
specify { expect(RubyEventStore::Configuration.new.loaded_defaults).to eq(RubyEventStore::VERSION) }
specify { expect(RubyEventStore::Configuration.new.test).to eq("current_value") }
specify { expect(RubyEventStore::Configuration.new.load_defaults("1.0.0").test).to eq("current_value") }
specify { expect(RubyEventStore::Configuration.new.load_defaults("2.17.0").test).to eq("new_value") }
specify { expect(RubyEventStore::Configuration.new.load_defaults("2.20.0").test).to eq("new_value") }

specify { expect(RubyEventStore.configuration).to be_a(RubyEventStore::Configuration) }
specify do
RubyEventStore.configure do |config|
config.load_defaults("2.0.0")
config.test = "another_value"
end
expect(RubyEventStore.configuration.loaded_defaults).to eq("2.0.0")
expect(RubyEventStore.configuration.test).to eq("another_value")
end
end
end