settingson 1.5.14 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/settingson/base.rb +23 -19
- data/lib/settingson/config.rb +2 -0
- data/lib/settingson/version.rb +1 -1
- 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: f3c4ea80ad5fe66fef73ce4715f535030f1836bf
|
4
|
+
data.tar.gz: c42f01d41f391c94da05d0b13ab37ced34f562db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d1e7603d60e6a47402f5d332b1fff7eb4e6905610329068fac2211040508862b689847a866fb4ea00ce4a8d28d883445d2a4345ff25891fa90ba2d537ad6bfd
|
7
|
+
data.tar.gz: ca5dffb1c631e00f8a25d7bb706e64b075eadf3c07678b272400fc78ebf9d7b55d992c2706aa32fa1955ee9aa1a8401bca05f45d5d7490f2ac4b8d58cafe1cfa
|
@@ -75,13 +75,17 @@ module Settingson::Base
|
|
75
75
|
included do
|
76
76
|
attr_accessor :settingson
|
77
77
|
serialize :value
|
78
|
-
before_destroy :
|
78
|
+
before_destroy :__delete_cached
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
81
|
+
def __debug(message)
|
82
|
+
Rails.logger.debug(message) if self.class.configure.debug
|
83
|
+
end
|
84
|
+
|
85
|
+
def __delete_cached
|
82
86
|
cache_key = "#{self.class.configure.cache.namespace}/#{self.key}"
|
83
87
|
Rails.cache.delete(cache_key)
|
84
|
-
|
88
|
+
__debug("#{self.class.name}: delete '#{self.key}' '#{cache_key}'")
|
85
89
|
end
|
86
90
|
|
87
91
|
def to_s
|
@@ -105,51 +109,51 @@ module Settingson::Base
|
|
105
109
|
def method_missing(symbol, *args)
|
106
110
|
super
|
107
111
|
rescue NameError
|
108
|
-
|
112
|
+
__rescue_action(symbol.to_s, args.first)
|
109
113
|
rescue NoMethodError
|
110
|
-
|
114
|
+
__rescue_action(symbol.to_s, args.first)
|
111
115
|
end # method_missing
|
112
116
|
|
113
117
|
protected
|
114
118
|
|
115
|
-
def
|
119
|
+
def __cached_key
|
116
120
|
[ self.class.configure.cache.namespace, @settingson ].join('/')
|
117
121
|
end
|
118
122
|
|
119
|
-
def
|
123
|
+
def __rescue_action(key, value)
|
120
124
|
case key
|
121
125
|
when /(.+)=/ # setter
|
122
126
|
@settingson = [@settingson, $1].compact.join('.')
|
123
127
|
record = self.class.find_or_create_by!(key: @settingson)
|
124
128
|
record.update!(value: value)
|
125
|
-
Rails.cache.write(
|
126
|
-
|
129
|
+
Rails.cache.write(__cached_key, value)
|
130
|
+
__debug("#{self.class.name}##{__method__} setter '#{__cached_key}'")
|
127
131
|
record.value
|
128
132
|
else # returns values or self
|
129
133
|
@settingson = [@settingson, key].compact.join('.')
|
130
|
-
|
131
|
-
|
134
|
+
__debug("#{self.class.name}##{__method__} getter '#{@settingson}'")
|
135
|
+
__cached_value_or_self
|
132
136
|
end
|
133
137
|
end
|
134
138
|
|
135
|
-
def
|
136
|
-
result =
|
139
|
+
def __cached_value_or_self
|
140
|
+
result = __cached_value
|
137
141
|
result.is_a?(ActiveRecord::RecordNotFound) ? self : result
|
138
142
|
end
|
139
143
|
|
140
|
-
def
|
141
|
-
|
144
|
+
def __cached_value
|
145
|
+
__debug("#{self.class.name}##{__method__} '#{@settingson}'")
|
142
146
|
Rails.cache.fetch(
|
143
|
-
|
147
|
+
__cached_key,
|
144
148
|
expires_in: self.class.configure.cache.expires,
|
145
149
|
race_condition_ttl: self.class.configure.cache.race_condition_ttl
|
146
150
|
) do
|
147
|
-
|
148
|
-
|
151
|
+
__debug("#{self.class.name}: fresh '#{@settingson}'")
|
152
|
+
__fresh_value
|
149
153
|
end
|
150
154
|
end
|
151
155
|
|
152
|
-
def
|
156
|
+
def __fresh_value
|
153
157
|
self.class.find_by!(key: @settingson).value
|
154
158
|
rescue ActiveRecord::RecordNotFound
|
155
159
|
ActiveRecord::RecordNotFound.new
|
data/lib/settingson/config.rb
CHANGED
data/lib/settingson/version.rb
CHANGED