rails-settings-cached 2.5.3 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails-settings/base.rb +16 -2
- data/lib/rails-settings/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 659ee746f1a087bb3ee48bba9f72a3dfd6af920830c6b003fd3bd909dce0a3c9
|
4
|
+
data.tar.gz: bb07a004ae0bbe413df58a0e2fd72fa7940cf5c55661c30214161745ebc5accc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cbd53148b2110e12e8280a34691e9c08fb1e0805d2cc3ce8a4d25bbb477339e0116d508bac3bfb988bd96ffd3c173838475b5c85bb4659644b275585870198f
|
7
|
+
data.tar.gz: afe704c8920d76f70795ad55ac17a5ccbfa9807abe9903090fa797b1eb9a7ac4c5564b0a817ccca329b57704eebd3d688ad347c1f6afce58b4fbb58e20a029a1
|
data/lib/rails-settings/base.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RailsSettings
|
4
|
-
class
|
5
|
-
|
4
|
+
class ProcetedKeyError < RuntimeError
|
5
|
+
def initialize(key)
|
6
|
+
super("Can't use #{key} as setting key.")
|
7
|
+
end
|
8
|
+
end
|
6
9
|
|
10
|
+
class Base < ActiveRecord::Base
|
7
11
|
SEPARATOR_REGEXP = /[\n,;]+/
|
12
|
+
PROTECTED_KEYS = %w[var value]
|
8
13
|
self.table_name = table_name_prefix + "settings"
|
9
14
|
|
10
15
|
# get the value field, YAML decoded
|
@@ -64,6 +69,8 @@ module RailsSettings
|
|
64
69
|
def _define_field(key, default: nil, type: :string, readonly: false, separator: nil, validates: nil)
|
65
70
|
key = key.to_s
|
66
71
|
|
72
|
+
raise ProcetedKeyError.new(key) if PROTECTED_KEYS.include?(key)
|
73
|
+
|
67
74
|
@defined_fields ||= []
|
68
75
|
@defined_fields << {
|
69
76
|
key: key,
|
@@ -120,6 +127,13 @@ module RailsSettings
|
|
120
127
|
send(key)
|
121
128
|
end
|
122
129
|
end
|
130
|
+
|
131
|
+
# delegate instance get method to class for support:
|
132
|
+
# setting = Setting.new
|
133
|
+
# setting.admin_emails
|
134
|
+
define_method(key) do
|
135
|
+
self.class.public_send(key)
|
136
|
+
end
|
123
137
|
end
|
124
138
|
|
125
139
|
def _convert_string_to_typeof_value(type, value, separator: nil)
|