rails_admin_settings 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rails_admin_settings/settings.rb +18 -5
- data/lib/rails_admin_settings/version.rb +1 -1
- data/spec/defaults_spec.rb +26 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71d5b091e4c98ce03f6c83d05f0d9d0bddb5943e
|
4
|
+
data.tar.gz: 8d68636b7c7b276e6a1590ad29fa0c01edde4bb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 440fc5862b70524e11c265c44b5676b11728128165f3b1f8dba738d8bc1220843dc3af58c7fdcff0c5ff57f5da2736f6efdd1065cf6a7edef4d52815925ebe8f
|
7
|
+
data.tar.gz: 92e113cef2735cbaabd77b289ed8e7e6e2b757fee3405e34cba81cb969239f90b0eb55fc0999d596daa69b4596caf4a73a0ed69961ba992acd57c28c0dc47b1a
|
@@ -9,11 +9,18 @@ class Settings < BasicObject
|
|
9
9
|
@@namespaces = {}
|
10
10
|
@@mutex = ::Mutex.new
|
11
11
|
|
12
|
+
cattr_accessor :ns_default, :ns_fallback
|
13
|
+
@@ns_default = 'main'
|
14
|
+
@@ns_fallback = nil
|
15
|
+
|
16
|
+
|
17
|
+
|
12
18
|
class << self
|
13
19
|
def ns(name, options = {})
|
14
20
|
options.symbolize_keys!
|
15
|
-
if name.nil?
|
16
|
-
name =
|
21
|
+
if name.nil? || name == 'main'
|
22
|
+
name = @@ns_default.to_s
|
23
|
+
options[:fallback] = @@ns_fallback.to_s
|
17
24
|
else
|
18
25
|
name = name.to_s
|
19
26
|
end
|
@@ -27,10 +34,16 @@ class Settings < BasicObject
|
|
27
34
|
end
|
28
35
|
end
|
29
36
|
|
37
|
+
def get_default_ns
|
38
|
+
ns(@@ns_default, fallback: @@ns_fallback)
|
39
|
+
end
|
40
|
+
|
30
41
|
def unload!
|
31
42
|
@@mutex.synchronize do
|
32
43
|
@@namespaces.values.map(&:unload!)
|
33
44
|
@@namespaces = {}
|
45
|
+
@@ns_default = 'main'
|
46
|
+
@@ns_fallback = nil
|
34
47
|
end
|
35
48
|
end
|
36
49
|
|
@@ -74,7 +87,7 @@ class Settings < BasicObject
|
|
74
87
|
options.symbolize_keys!
|
75
88
|
|
76
89
|
if options[:ns].nil? || options[:ns].to_s == 'main'
|
77
|
-
|
90
|
+
get_default_ns.get(key, options)
|
78
91
|
else
|
79
92
|
ns(options[:ns]).get(key, options)
|
80
93
|
end
|
@@ -84,7 +97,7 @@ class Settings < BasicObject
|
|
84
97
|
options.symbolize_keys!
|
85
98
|
|
86
99
|
if options[:ns].nil? || options[:ns].to_s == 'main'
|
87
|
-
|
100
|
+
get_default_ns.set(key, value, options)
|
88
101
|
else
|
89
102
|
ns(options[:ns]).set(key, value, options)
|
90
103
|
end
|
@@ -99,7 +112,7 @@ class Settings < BasicObject
|
|
99
112
|
end
|
100
113
|
|
101
114
|
def method_missing(*args)
|
102
|
-
|
115
|
+
get_default_ns.__send__(*args)
|
103
116
|
end
|
104
117
|
end
|
105
118
|
end
|
data/spec/defaults_spec.rb
CHANGED
@@ -43,6 +43,32 @@ describe 'Settings loading defaults' do
|
|
43
43
|
Settings.ns(:etc, fallback: :other).footer.should eq 'zzz'
|
44
44
|
end
|
45
45
|
|
46
|
+
it 'works with custom default namespace' do
|
47
|
+
Settings.ns_default = 'other'
|
48
|
+
Settings.ns_fallback = 'other'
|
49
|
+
Settings.ns(:main).phone.should eq '906 1111111'
|
50
|
+
Settings.ns(:other).footer.should eq 'zzz'
|
51
|
+
Settings.ns(:main).footer.should eq 'test <b></b>'
|
52
|
+
Settings.footer.should eq 'zzz'
|
53
|
+
|
54
|
+
Settings.ns(:etc, fallback: :main).phone.should eq '906 1111111'
|
55
|
+
Settings.ns(:etc, fallback: :main).footer.should eq 'test <b></b>'
|
56
|
+
Settings.ns(:other, fallback: :main).footer.should eq 'zzz'
|
57
|
+
Settings.ns(:etc, fallback: :other).footer.should eq 'zzz'
|
58
|
+
|
59
|
+
Settings.ns_default = :etc
|
60
|
+
Settings.ns_fallback = :main
|
61
|
+
Settings.phone.should eq '906 1111111'
|
62
|
+
Settings.footer.should eq 'test <b></b>'
|
63
|
+
|
64
|
+
Settings.ns_fallback = :other
|
65
|
+
Settings.footer.should eq 'zzz'
|
66
|
+
|
67
|
+
Settings.ns_default = :other
|
68
|
+
Settings.ns_fallback = :main
|
69
|
+
Settings.footer.should eq 'zzz'
|
70
|
+
end
|
71
|
+
|
46
72
|
it "doesn't overwrite" do
|
47
73
|
Settings.ns(:main).phone = '906 2222222'
|
48
74
|
Settings.ns(:other).footer = 'xxx'
|