ack_rails_admin_settings 1.2.1.3 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +4 -4
- data/app/models/rails_admin_settings/setting.rb +4 -0
- data/lib/rails_admin_settings/fallback.rb +7 -2
- data/lib/rails_admin_settings/mongoid.rb +15 -2
- data/lib/rails_admin_settings/namespaced.rb +98 -31
- data/lib/rails_admin_settings/rails_admin_config.rb +3 -0
- data/lib/rails_admin_settings/require_helpers.rb +1 -1
- data/lib/rails_admin_settings/settings.rb +10 -2
- data/lib/rails_admin_settings/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 624635c832be44255141d7ada5d09cc18abf8b89
|
4
|
+
data.tar.gz: d0a9ed54f0ca8df937ac06fbcd51364f58a61c02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46e9b4192e3b1b9e83129de9abb34ac8b59abe36d97a2a01cd4484309a3b61fc61948bb4812416152b25e20e2c0e2b7cabc6de4908d3f4442180bb33f65e3931
|
7
|
+
data.tar.gz: 7a0dbcf80aee6d511d2b572caf2af051fdce29628b8a0b987d2e0937a9aa157218e64e4cc2ef1615f4940aae5c61dcc51464e33447c4169892a9e2492924c19b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 1.2.2
|
2
|
+
- Loadable Settings. You can cancel load some settings for save time, memory, etc. Because of cache, perhaps.
|
3
|
+
- DELEGATE :p, :puts and :block_given? for Kernel. Prevent Settings.p and etc
|
4
|
+
- Caching improves.
|
5
|
+
|
1
6
|
## 1.2.1
|
2
7
|
|
3
8
|
- Remove HancockCMS support (moved into CMS and cache plugin for CMS).
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ack_rails_admin_settings (1.2.
|
4
|
+
ack_rails_admin_settings (1.2.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -65,7 +65,7 @@ GEM
|
|
65
65
|
erubis (2.7.0)
|
66
66
|
factory_girl (4.8.0)
|
67
67
|
activesupport (>= 3.0.0)
|
68
|
-
geocoder (1.4.
|
68
|
+
geocoder (1.4.3)
|
69
69
|
glebtv-carrierwave-mongoid (0.7.0)
|
70
70
|
carrierwave (~> 0.9.0)
|
71
71
|
mongoid (~> 4.0.0.alpha1)
|
@@ -74,7 +74,7 @@ GEM
|
|
74
74
|
paperclip (~> 5.1.0)
|
75
75
|
globalid (0.3.7)
|
76
76
|
activesupport (>= 4.1.0)
|
77
|
-
i18n (0.
|
77
|
+
i18n (0.8.0)
|
78
78
|
json (2.0.3)
|
79
79
|
loofah (2.0.3)
|
80
80
|
nokogiri (>= 1.5.9)
|
@@ -164,7 +164,7 @@ GEM
|
|
164
164
|
crass (~> 1.0.2)
|
165
165
|
nokogiri (>= 1.4.4)
|
166
166
|
nokogumbo (~> 1.4.1)
|
167
|
-
simplecov (0.
|
167
|
+
simplecov (0.13.0)
|
168
168
|
docile (~> 1.1.0)
|
169
169
|
json (>= 1.8, < 3)
|
170
170
|
simplecov-html (~> 0.10.0)
|
@@ -2,6 +2,9 @@ module RailsAdminSettings
|
|
2
2
|
# we are inheriting from BasicObject so we don't get a bunch of methods from
|
3
3
|
# Kernel or Object
|
4
4
|
class Fallback < BasicObject
|
5
|
+
|
6
|
+
DELEGATE = [:puts, :p, :block_given?].freeze
|
7
|
+
|
5
8
|
def initialize(ns, fb)
|
6
9
|
@ns = ns
|
7
10
|
@fb = fb
|
@@ -11,10 +14,12 @@ module RailsAdminSettings
|
|
11
14
|
"#<RailsAdminSettings::Fallback ns: #{@ns.inspect}, fb: #{@fb.inspect}>".freeze
|
12
15
|
end
|
13
16
|
|
14
|
-
def method_missing(*args)
|
17
|
+
def method_missing(name, *args, &block)
|
18
|
+
return ::Kernel.send(name, *args, &block) if DELEGATE.include?(name)
|
19
|
+
|
15
20
|
@ns.ns_mutex.synchronize do
|
16
21
|
@ns.fallback = @fb
|
17
|
-
@ns.__send__(*args)
|
22
|
+
@ns.__send__(name, *args, &block)
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -12,11 +12,24 @@ module RailsAdminSettings
|
|
12
12
|
field :key, type: String
|
13
13
|
field :raw, type: String
|
14
14
|
field :label, type: String
|
15
|
-
|
15
|
+
field :loadable, type: Boolean, default: true
|
16
|
+
scope :loadable, -> {
|
17
|
+
where(loadable: true)
|
18
|
+
}
|
19
|
+
index({ns: 1, key: 1, loadable: 1}, {unique: true, sparse: true})
|
16
20
|
|
17
21
|
field :cache_keys_str, type: String, default: ""
|
18
22
|
def cache_keys
|
19
|
-
cache_keys_str.split(/\s+/).map { |k| k.strip }.reject { |k| k.blank? }
|
23
|
+
@cache_keys ||= cache_keys_str.split(/\s+/).map { |k| k.strip }.reject { |k| k.blank? }
|
24
|
+
end
|
25
|
+
def add_cache_key(_key)
|
26
|
+
unless has_cache_key?(_key)
|
27
|
+
self.cache_keys_str = (cache_keys + [_key]).uniq.join(" ")
|
28
|
+
@cache_key = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
def has_cache_key?(_key)
|
32
|
+
cache_keys.include?(_key)
|
20
33
|
end
|
21
34
|
|
22
35
|
after_touch :clear_cache
|
@@ -2,6 +2,9 @@ module RailsAdminSettings
|
|
2
2
|
# we are inheriting from BasicObject so we don't get a bunch of methods from
|
3
3
|
# Kernel or Object
|
4
4
|
class Namespaced < BasicObject
|
5
|
+
|
6
|
+
DELEGATE = [:puts, :p, :block_given?].freeze
|
7
|
+
|
5
8
|
attr_accessor :settings, :fallback
|
6
9
|
attr_reader :loaded, :mutex, :ns_mutex, :name
|
7
10
|
|
@@ -29,7 +32,7 @@ module RailsAdminSettings
|
|
29
32
|
return if loaded
|
30
33
|
@loaded = true
|
31
34
|
@settings = {}
|
32
|
-
::RailsAdminSettings::Setting.ns(@name).each do |setting|
|
35
|
+
::RailsAdminSettings::Setting.ns(@name).loadable.each do |setting|
|
33
36
|
@settings[setting.key] = setting
|
34
37
|
end
|
35
38
|
end
|
@@ -43,18 +46,63 @@ module RailsAdminSettings
|
|
43
46
|
end
|
44
47
|
|
45
48
|
# returns setting object
|
46
|
-
def get(key, options = {})
|
47
|
-
|
49
|
+
def get(key, options = {}, &block)
|
50
|
+
options[:loadable] = true unless options[:loadable] == false
|
51
|
+
load! if options[:loadable]
|
48
52
|
key = key.to_s
|
49
53
|
mutex.synchronize do
|
50
54
|
@locked = true
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
_loadable = options[:loadable]
|
56
|
+
unless _loadable
|
57
|
+
v = ::RailsAdminSettings::Setting.ns(name).where(key: key).first
|
58
|
+
if v
|
59
|
+
unless options[:cache_keys_str].present?
|
60
|
+
_cache_keys = options.delete(:cache_keys)
|
61
|
+
_cache_keys ||= options.delete(:cache_key)
|
62
|
+
|
63
|
+
if _cache_keys.nil?
|
64
|
+
# if _cache
|
65
|
+
# options[:cache_keys_str] = name.underscore
|
66
|
+
# end
|
67
|
+
else
|
68
|
+
if _cache_keys.is_a?(::Array)
|
69
|
+
options[:cache_keys_str] = _cache_keys.map { |k| k.to_s.strip }.join(" ")
|
70
|
+
else
|
71
|
+
options[:cache_keys_str] = _cache_keys.to_s.strip
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
options.delete(:cache_keys)
|
76
|
+
options.delete(:cache_key)
|
77
|
+
|
78
|
+
_old_cache_keys = options[:cache_keys_str].strip.split(" ")
|
79
|
+
# options[:cache_keys_str] = ("#{v.cache_keys_str} #{(options[:cache_keys_str] || "")}".strip.split(" ")).uniq
|
80
|
+
# options[:cache_keys_str] = ("#{v.cache_keys_str.join(" ")} #{(options[:cache_keys_str] || "")}".strip.split(" ")).uniq
|
81
|
+
options[:cache_keys_str] = (_old_cache_keys + v.cache_keys).uniq
|
82
|
+
options[:overwrite] = true if (options[:cache_keys_str] - _old_cache_keys).blank?
|
83
|
+
options[:cache_keys_str] = options[:cache_keys_str].map { |k| k.to_s.strip }.join(" ")
|
55
84
|
end
|
85
|
+
else
|
86
|
+
v = @settings[key]
|
87
|
+
end
|
88
|
+
_overwrite = options[:overwrite]
|
89
|
+
if v.nil? or _overwrite
|
56
90
|
if v.nil?
|
57
|
-
|
91
|
+
unless @fallback.nil? || @fallback == @name
|
92
|
+
v = ::Settings.ns(@fallback).getnc(key)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
if v.nil? or _overwrite
|
96
|
+
if block
|
97
|
+
begin
|
98
|
+
v = set(key, yield, options)
|
99
|
+
rescue Exception => ex
|
100
|
+
# puts "WTF"
|
101
|
+
# puts ex.inspect
|
102
|
+
end
|
103
|
+
else
|
104
|
+
v = set(key, options[:default], options)
|
105
|
+
end
|
58
106
|
end
|
59
107
|
end
|
60
108
|
@locked = false
|
@@ -65,13 +113,17 @@ module RailsAdminSettings
|
|
65
113
|
# returns setting object
|
66
114
|
def getnc(key)
|
67
115
|
load!
|
68
|
-
mutex.synchronize do
|
116
|
+
ret = mutex.synchronize do
|
69
117
|
self.settings[key]
|
70
118
|
end
|
119
|
+
unless ret
|
120
|
+
ret = ::RailsAdminSettings::Setting.ns(name).where(key: key).first
|
121
|
+
end
|
122
|
+
ret
|
71
123
|
end
|
72
124
|
|
73
125
|
def set(key, value = nil, options = {})
|
74
|
-
load! unless @locked
|
126
|
+
load! unless @locked if options[:loadable]
|
75
127
|
key = key.to_s
|
76
128
|
options.symbolize_keys!
|
77
129
|
if options.key?(:cache)
|
@@ -87,8 +139,8 @@ module RailsAdminSettings
|
|
87
139
|
end
|
88
140
|
|
89
141
|
unless options[:cache_keys_str].present?
|
90
|
-
|
91
|
-
_cache_keys
|
142
|
+
_cache_keys = options.delete(:cache_keys)
|
143
|
+
_cache_keys ||= options.delete(:cache_key)
|
92
144
|
|
93
145
|
if _cache_keys.nil?
|
94
146
|
# if _cache
|
@@ -96,21 +148,24 @@ module RailsAdminSettings
|
|
96
148
|
# end
|
97
149
|
else
|
98
150
|
if _cache_keys.is_a?(::Array)
|
99
|
-
options[:cache_keys_str] = _cache_keys.map { |k| k.to_s }.join(" ")
|
151
|
+
options[:cache_keys_str] = _cache_keys.map { |k| k.to_s.strip }.join(" ")
|
100
152
|
else
|
101
|
-
options[:cache_keys_str] = _cache_keys.to_s
|
153
|
+
options[:cache_keys_str] = _cache_keys.to_s.strip
|
102
154
|
end
|
103
155
|
end
|
104
156
|
end
|
157
|
+
options.delete(:cache_keys)
|
158
|
+
options.delete(:cache_key)
|
105
159
|
|
106
160
|
options.merge!(value: value)
|
107
161
|
if @locked
|
108
|
-
write_to_database(key, options)
|
162
|
+
ret = write_to_database(key, options)
|
109
163
|
else
|
110
164
|
mutex.synchronize do
|
111
|
-
write_to_database(key, options)
|
165
|
+
ret = write_to_database(key, options)
|
112
166
|
end
|
113
167
|
end
|
168
|
+
ret
|
114
169
|
end
|
115
170
|
|
116
171
|
def enabled?(key, options = {})
|
@@ -142,7 +197,8 @@ module RailsAdminSettings
|
|
142
197
|
end
|
143
198
|
|
144
199
|
# returns processed setting value
|
145
|
-
def method_missing(key, *args)
|
200
|
+
def method_missing(key, *args, &block)
|
201
|
+
return ::Kernel.send(key, *args, &block) if DELEGATE.include?(key)
|
146
202
|
key = key.to_s
|
147
203
|
if key.end_with?('_enabled?')
|
148
204
|
key = key[0..-10]
|
@@ -172,7 +228,7 @@ module RailsAdminSettings
|
|
172
228
|
value = args.first
|
173
229
|
set(key, value, options).val
|
174
230
|
else
|
175
|
-
v = get(key, args.first || {})
|
231
|
+
v = get(key, args.first || {}, &block)
|
176
232
|
if v.nil?
|
177
233
|
''
|
178
234
|
else
|
@@ -187,27 +243,38 @@ module RailsAdminSettings
|
|
187
243
|
options[:raw] = ''
|
188
244
|
file = options[:value]
|
189
245
|
else
|
190
|
-
options[:raw] = options[:value]
|
246
|
+
options[:raw] = options[:value] if options[:value]
|
191
247
|
end
|
192
248
|
|
193
249
|
options.delete(:value)
|
194
250
|
options.delete(:default)
|
195
251
|
options[:ns] = @name
|
196
|
-
|
197
252
|
if @settings[key].nil?
|
198
|
-
options.delete(:overwrite)
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
v
|
203
|
-
|
204
|
-
|
253
|
+
if options.delete(:overwrite)
|
254
|
+
v = ::RailsAdminSettings::Setting.ns(options[:ns]).where(key: key).first
|
255
|
+
if v
|
256
|
+
opts = options.dup
|
257
|
+
v.update_attributes!(opts)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
if v.nil?
|
261
|
+
v = ::RailsAdminSettings::Setting.create(options.merge(key: key))
|
262
|
+
if !v.persisted?
|
263
|
+
if v.errors[:key].any?
|
264
|
+
v = ::RailsAdminSettings::Setting.where(key: key).first
|
265
|
+
if v.nil?
|
266
|
+
::Kernel.raise ::RailsAdminSettings::PersistenceException, 'Fatal: error in key and not in DB'
|
267
|
+
end
|
268
|
+
else
|
269
|
+
::Kernel.raise ::RailsAdminSettings::PersistenceException, v.errors.full_messages.join(',')
|
205
270
|
end
|
206
|
-
else
|
207
|
-
::Kernel.raise ::RailsAdminSettings::PersistenceException, v.errors.full_messages.join(',')
|
208
271
|
end
|
209
272
|
end
|
210
|
-
|
273
|
+
if options[:loadable]
|
274
|
+
@settings[key] = v
|
275
|
+
else
|
276
|
+
return v
|
277
|
+
end
|
211
278
|
else
|
212
279
|
opts = options.dup
|
213
280
|
if options[:overwrite] == false && !@settings[key].value.blank?
|
@@ -218,7 +285,7 @@ module RailsAdminSettings
|
|
218
285
|
opts.delete(:overwrite)
|
219
286
|
@settings[key].update_attributes!(opts)
|
220
287
|
end
|
221
|
-
if is_file
|
288
|
+
if is_file and options[:loadable] and @settings[key]
|
222
289
|
if options[:overwrite] != false || !@settings[key].file?
|
223
290
|
@settings[key].file = file
|
224
291
|
@settings[key].save!
|
@@ -10,8 +10,10 @@ module RailsAdminSettings
|
|
10
10
|
list do
|
11
11
|
if Object.const_defined?('RailsAdminToggleable')
|
12
12
|
field :enabled, :toggle
|
13
|
+
field :loadable, :toggle
|
13
14
|
else
|
14
15
|
field :enabled
|
16
|
+
field :loadable
|
15
17
|
end
|
16
18
|
field :kind do
|
17
19
|
searchable true
|
@@ -50,6 +52,7 @@ module RailsAdminSettings
|
|
50
52
|
|
51
53
|
edit do
|
52
54
|
field :enabled
|
55
|
+
field :loadable
|
53
56
|
field :ns do
|
54
57
|
read_only true
|
55
58
|
help false
|
@@ -47,7 +47,7 @@ module RailsAdminSettings
|
|
47
47
|
require 'geocoder'
|
48
48
|
yield
|
49
49
|
rescue LoadError => e
|
50
|
-
e.message << " [rails_admin_settings] Please add gem '
|
50
|
+
e.message << " [rails_admin_settings] Please add gem 'geocoder' to your Gemfile to use geocoder kind settings".freeze
|
51
51
|
raise e
|
52
52
|
end
|
53
53
|
end
|
@@ -3,6 +3,9 @@ require 'thread'
|
|
3
3
|
# we are inheriting from BasicObject so we don't get a bunch of methods from
|
4
4
|
# Kernel or Object
|
5
5
|
class Settings < BasicObject
|
6
|
+
|
7
|
+
DELEGATE = [:puts, :p, :block_given?].freeze
|
8
|
+
|
6
9
|
cattr_accessor :file_uploads_supported, :file_uploads_engine
|
7
10
|
@@file_uploads_supported = false
|
8
11
|
@@file_uploads_engine = false
|
@@ -106,8 +109,13 @@ class Settings < BasicObject
|
|
106
109
|
set(key, nil, options.merge(overwrite: false))
|
107
110
|
end
|
108
111
|
|
109
|
-
def method_missing(*args)
|
110
|
-
|
112
|
+
def method_missing(name, *args, &block)
|
113
|
+
return ::Kernel.send(name, *args, &block) if DELEGATE.include?(name)
|
114
|
+
get_default_ns.__send__(name, *args, &block)
|
115
|
+
end
|
116
|
+
|
117
|
+
def respond_to_missing?(name, include_private = false)
|
118
|
+
DELEGATE.include?(name) or super
|
111
119
|
end
|
112
120
|
end
|
113
121
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ack_rails_admin_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kiseliev
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|