-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement configurable storage backend (#242)
* Implement configurable storage backend * Refactor `Configuration` class and its usage * Update tests * Fix flake test
- Loading branch information
1 parent
fce56c6
commit 95f538f
Showing
6 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module RailsSettings | ||
class Configuration | ||
# Caching storage backend. | ||
# Default: `Rails.cache` | ||
attr_accessor :cache_storage | ||
end | ||
|
||
class << self | ||
def config | ||
return @config if defined?(@config) | ||
|
||
@config = Configuration.new | ||
@config.cache_storage = Rails.cache | ||
@config | ||
end | ||
|
||
def configure(&block) | ||
config.instance_exec(&block) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class ConfigurationTest < ActiveSupport::TestCase | ||
test "configuration" do | ||
RailsSettings.configure do | ||
self.cache_storage = ActiveSupport::Cache.lookup_store(:dummy_store) | ||
end | ||
|
||
assert RailsSettings.config.cache_storage.instance_of? ActiveSupport::Cache::DummyStore | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveSupport | ||
module Cache | ||
class DummyStore < Store | ||
attr_reader :data | ||
|
||
def initialize(options = {}) | ||
super(options) | ||
|
||
@data = {} | ||
end | ||
|
||
def read_entry(key, **options) | ||
data[key] | ||
end | ||
|
||
def write_entry(key, value, **options) | ||
data[key] = value | ||
end | ||
|
||
def delete_entry(key, **options) | ||
data.delete(key) | ||
end | ||
end | ||
end | ||
end |