Skip to content

Commit 3fb6a59

Browse files
committed
Lazy load settings and removed deprecation warning in comments config
1 parent 496432a commit 3fb6a59

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

lib/active_admin/application.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class Application
5858
include AssetRegistration
5959

6060
def initialize
61-
initialize_defaults!
6261
register_default_assets
6362
end
6463

lib/active_admin/comments/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Configuration
99
#
1010
# config.allow_comments_in = [:admin, :root]
1111
#
12-
attr_accessor_with_default :allow_comments_in, [:admin]
12+
setting :allow_comments_in, [:admin]
1313
end
1414

1515
end

lib/active_admin/helpers/settings.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,25 @@ def default_settings
2525
self.class.default_settings
2626
end
2727

28-
def initialize_defaults!
29-
default_settings.each do |key, value|
30-
send("#{key}=".to_sym, value)
31-
end
32-
end
33-
3428
end
3529

3630
module ClassMethods
3731

3832
def setting(name, default)
3933
default_settings[name] = default
4034
attr_accessor(name)
35+
36+
# Create an accessor that grabs from the defaults
37+
# if @name has not been set yet
38+
class_eval <<-EOC, __FILE__, __LINE__
39+
def #{name}
40+
if instance_variable_defined? :@#{name}
41+
@#{name}
42+
else
43+
default_settings[:#{name}]
44+
end
45+
end
46+
EOC
4147
end
4248

4349
def default_settings

spec/unit/helpers/settings_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
let(:klass) do
88
Class.new do
99
include ActiveAdmin::Settings
10-
def initialize
11-
initialize_defaults!
12-
end
1310
end
1411
end
1512

@@ -23,4 +20,11 @@ def initialize
2320
klass.new.my_setting.should == "Hello World"
2421
end
2522

23+
it "should support settings of nil" do
24+
klass.setting :my_setting, :some_val
25+
inst = klass.new
26+
inst.my_setting = nil
27+
inst.my_setting.should == nil
28+
end
29+
2630
end

0 commit comments

Comments
 (0)