Skip to content

Commit a9714fe

Browse files
committed
Configuration: Add #configure syntax sugar
This allows us to do ``` Alchemy.configure do |config| config.user_class = "Spree::User" end ```
1 parent bdb6661 commit a9714fe

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

lib/alchemy.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ class << self
2121
def config
2222
@_config ||= Alchemy::Configurations::Main.new
2323
end
24-
25-
def configure(&blk)
26-
yield config
27-
end
24+
delegate :configure, to: :config
2825

2926
enable_searchable_deprecation_msg = "Use `Alchemy.config.show_page_searchable_checkbox` instead."
3027
def enable_searchable = config.show_page_searchable_checkbox

lib/alchemy/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def set(configuration_hash)
3939

4040
alias_method :get, :send
4141
alias_method :[], :get
42+
alias_method :configure, :tap
4243

4344
def show = self
4445

spec/libraries/alchemy/configuration_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050
expect(configuration.fetch("auto_logout_time", 20)).to eq(40)
5151
end
5252
end
53+
54+
describe "#configure" do
55+
it "yields self" do
56+
configuration.configure do |conf|
57+
conf.auto_logout_time = 15
58+
end
59+
expect(configuration.auto_logout_time).to eq(15)
60+
end
61+
end
5362
end
5463

5564
context "setting with the wrong type" do

0 commit comments

Comments
 (0)