File tree Expand file tree Collapse file tree 6 files changed +25
-64
lines changed Expand file tree Collapse file tree 6 files changed +25
-64
lines changed Original file line number Diff line number Diff line change @@ -7,33 +7,28 @@ class Application
7
7
8
8
class << self
9
9
def default_settings
10
- @settings ||= SettingsNode . new
10
+ @settings ||= SettingsNode . build
11
11
end
12
12
13
13
def namespace_default_settings
14
- @namespace_settings ||= SettingsNode . new
14
+ @namespace_settings ||= SettingsNode . build
15
15
end
16
16
17
17
def setting ( name , default )
18
- default_settings . settings [ name ] = default
18
+ default_settings . register name , default
19
19
end
20
20
21
21
def inheritable_setting ( name , default )
22
- namespace_default_settings . settings [ name ] = default
23
- Namespace . default_settings . settings [ name ] = default
22
+ namespace_default_settings . register name , default
24
23
end
25
24
end
26
25
27
- def default_settings
28
- self . class . default_settings
29
- end
30
-
31
26
def settings
32
- @settings ||= SettingsNode . new ( self . class . default_settings )
27
+ @settings ||= SettingsNode . build ( self . class . default_settings )
33
28
end
34
29
35
30
def namespace_settings
36
- @namespace_settings ||= SettingsNode . new ( self . class . namespace_default_settings )
31
+ @namespace_settings ||= SettingsNode . build ( self . class . namespace_default_settings )
37
32
end
38
33
39
34
def respond_to_missing? ( method , include_private = false )
Original file line number Diff line number Diff line change 1
1
module ActiveAdmin
2
2
class Engine < ::Rails ::Engine
3
3
initializer "active_admin.load_app_path" do |app |
4
- ActiveAdmin . application . instance_exec ( app ) do |app |
5
- default_settings [ :app_path ] = app . root
6
- default_settings [ :load_paths ] = [ File . expand_path ( 'app/admin' , app . root ) ]
7
- end
4
+ ActiveAdmin ::Application . setting :app_path , app . root
5
+ ActiveAdmin ::Application . setting :load_paths , [ File . expand_path ( 'app/admin' , app . root ) ]
8
6
end
9
7
10
8
initializer "active_admin.precompile" , group : :all do |app |
Original file line number Diff line number Diff line change @@ -26,12 +26,8 @@ module ActiveAdmin
26
26
#
27
27
class Namespace
28
28
class << self
29
- def default_settings
30
- @settings ||= SettingsNode . new
31
- end
32
-
33
29
def setting ( name , default )
34
- default_settings . settings [ name ] = default
30
+ Deprecation . warn "This method does not do anything and will be removed."
35
31
end
36
32
end
37
33
@@ -52,7 +48,7 @@ def name
52
48
end
53
49
54
50
def settings
55
- @settings ||= SettingsNode . new ( application . namespace_settings )
51
+ @settings ||= SettingsNode . build ( application . namespace_settings )
56
52
end
57
53
58
54
def respond_to_missing? ( method , include_private = false )
Original file line number Diff line number Diff line change 1
1
module ActiveAdmin
2
2
3
3
class SettingsNode
4
- def initialize ( parent = nil )
5
- @parent = parent
6
- end
7
-
8
- def settings
9
- @settings ||= { }
10
- end
11
-
12
- delegate :[]= , to : :settings
13
-
14
- protected
15
-
16
- def parent
17
- @parent ||= self . class . new
18
- end
19
-
20
- def has_key? ( name )
21
- settings . has_key? ( name . to_sym ) || @parent && @parent . has_key? ( name . to_sym )
22
- end
4
+ class << self
5
+ # Never instantiated. Variables are stored in the singleton_class.
6
+ private_class_method :new
23
7
24
- def fetch ( name )
25
- if settings . has_key? ( name . to_sym )
26
- settings . fetch ( name . to_sym )
27
- elsif @parent
28
- parent . fetch ( name )
8
+ # @returns anonymous class with same accessors as the superclass.
9
+ def build ( superclass = SettingsNode )
10
+ Class . new ( superclass )
29
11
end
30
- end
31
-
32
- def respond_to_missing? ( method , include_private = false )
33
- has_key? ( method . to_s . chomp '=' ) || super
34
- end
35
12
36
- def method_missing ( method , *args )
37
- name = method . to_s
38
- if has_key? ( name .chomp '=' )
39
- if name . chomp! '='
40
- settings [ name . to_sym ] = args . first
41
- else
42
- fetch ( name )
43
- end
44
- else
45
- super
13
+ def register ( name , value )
14
+ class_attribute name
15
+ send "#{ name } =" , value
46
16
end
47
17
end
48
18
end
Original file line number Diff line number Diff line change 50
50
let ( :namespace ) { ActiveAdmin ::Namespace . new ( application , :admin ) }
51
51
52
52
it "should inherit the site title from the application" do
53
- ActiveAdmin ::Namespace . setting :site_title , "Not the Same"
53
+ ActiveSupport ::Deprecation . silence do
54
+ ActiveAdmin ::Namespace . setting :site_title , "Not the Same"
55
+ end
54
56
expect ( namespace . site_title ) . to eq application . site_title
55
57
end
56
58
Original file line number Diff line number Diff line change 1
1
require 'rails_helper'
2
2
3
3
RSpec . describe ActiveAdmin ::SettingsNode do
4
- subject { ActiveAdmin ::SettingsNode . new }
5
- let ( :child ) { ActiveAdmin ::SettingsNode . new ( subject ) }
4
+ subject { ActiveAdmin ::SettingsNode . build }
5
+ let! ( :child ) { ActiveAdmin ::SettingsNode . build ( subject ) }
6
6
7
7
context 'parent setting includes foo' do
8
- before { subject . settings [ :foo ] = true }
8
+ before { subject . register :foo , true }
9
9
10
10
it 'returns parent settings' do
11
11
expect ( child . foo ) . to eq true
You can’t perform that action at this time.
0 commit comments