rails_admin_settings 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ea98edd6e8bad6c86e500d5dffd7fb55588fcd4
4
- data.tar.gz: a5b9d884b4d4b5f7deeac4f3e46dc135e521721e
3
+ metadata.gz: 71d5b091e4c98ce03f6c83d05f0d9d0bddb5943e
4
+ data.tar.gz: 8d68636b7c7b276e6a1590ad29fa0c01edde4bb0
5
5
  SHA512:
6
- metadata.gz: 6e4348c966b49d6252543f12d00090bafcf302a98b8a456aa4776c6dc401aed384dcc93b9f5be4a47c67a01d18b0eeb22597142b6b7d54731ab2dffa44c3548c
7
- data.tar.gz: 378f2c80f910a6a73f25a4e70aebee49a4a812a5f315dfd20cb68003c8cd03ed1960c4aff8c82006b8b4bc22ae2849d1cad83ad2e8ae404b394468a5a8f1a148
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 = 'main'
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
- ns('main').get(key, options)
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
- ns('main').set(key, value, options)
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
- ns('main').__send__(*args)
115
+ get_default_ns.__send__(*args)
103
116
  end
104
117
  end
105
118
  end
@@ -1,3 +1,3 @@
1
1
  module RailsAdminSettings
2
- VERSION = "0.6.4"
2
+ VERSION = "0.6.5"
3
3
  end
@@ -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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Tv