File tree Expand file tree Collapse file tree 4 files changed +20
-11
lines changed Expand file tree Collapse file tree 4 files changed +20
-11
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+
2630end
You can’t perform that action at this time.
0 commit comments