rails-settings-cached 2.5.1 → 2.5.2
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 +17 -14
- data/lib/rails-settings/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e423b44c4e49c3d0ffb953ffee50e1b268262a770eba8a9114b23c494458861
|
4
|
+
data.tar.gz: d5997e14e9288ec4c0fdf858a1029ea3a379b1e1aecf05b2ed8bb9158bf45bbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edf9eff836688ce1f82d3de681c34a7fd9c782e526e952ac42430d7f559b7aae51c3f73f4a749f167302f31b4b3286dce2d5f21dc504a6735981db6a0d259b6f
|
7
|
+
data.tar.gz: dfcbf34fcbb3f0af4d0161601537db441c8d07632ffc2b964857b10fcaa6af8b88f2cbd2c758d21bf3e9676a7dc8a1ea607230c3e06560fcf65feef2c7fff434
|
data/lib/rails-settings/base.rb
CHANGED
@@ -28,7 +28,8 @@ module RailsSettings
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def field(key, **opts)
|
31
|
-
_define_field(key, default: opts[:default], type: opts[:type], readonly: opts[:readonly],
|
31
|
+
_define_field(key, default: opts[:default], type: opts[:type], readonly: opts[:readonly],
|
32
|
+
separator: opts[:separator], validates: opts[:validates])
|
32
33
|
end
|
33
34
|
|
34
35
|
def get_field(key)
|
@@ -60,9 +61,11 @@ module RailsSettings
|
|
60
61
|
private
|
61
62
|
|
62
63
|
def _define_field(key, default: nil, type: :string, readonly: false, separator: nil, validates: nil)
|
64
|
+
key = key.to_s
|
65
|
+
|
63
66
|
@defined_fields ||= []
|
64
67
|
@defined_fields << {
|
65
|
-
key: key
|
68
|
+
key: key,
|
66
69
|
default: default,
|
67
70
|
type: type || :string,
|
68
71
|
readonly: readonly.nil? ? false : readonly
|
@@ -89,7 +92,7 @@ module RailsSettings
|
|
89
92
|
end
|
90
93
|
|
91
94
|
define_singleton_method("#{key}=") do |value|
|
92
|
-
var_name = key
|
95
|
+
var_name = key
|
93
96
|
|
94
97
|
record = find_by(var: var_name) || new(var: var_name)
|
95
98
|
value = send(:_convert_string_to_typeof_value, type, value, separator: separator)
|
@@ -101,7 +104,7 @@ module RailsSettings
|
|
101
104
|
end
|
102
105
|
|
103
106
|
if validates
|
104
|
-
validates[:if] =
|
107
|
+
validates[:if] = proc { |item| item.var.to_s == key }
|
105
108
|
send(:validates, key, **validates)
|
106
109
|
|
107
110
|
define_method(:read_attribute_for_validation) do |_key|
|
@@ -122,19 +125,19 @@ module RailsSettings
|
|
122
125
|
|
123
126
|
case type
|
124
127
|
when :boolean
|
125
|
-
|
128
|
+
["true", "1", 1, true].include?(value)
|
126
129
|
when :array
|
127
130
|
value.split(separator || SEPARATOR_REGEXP).reject { |str| str.empty? }.map(&:strip)
|
128
131
|
when :hash
|
129
132
|
value = begin
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
133
|
+
begin
|
134
|
+
YAML.load(value).to_h
|
135
|
+
rescue StandardError
|
136
|
+
eval(value).to_h
|
137
|
+
end
|
138
|
+
rescue StandardError
|
139
|
+
{}
|
140
|
+
end
|
138
141
|
value.deep_stringify_keys!
|
139
142
|
ActiveSupport::HashWithIndifferentAccess.new(value)
|
140
143
|
when :integer
|
@@ -155,7 +158,7 @@ module RailsSettings
|
|
155
158
|
return nil
|
156
159
|
end
|
157
160
|
|
158
|
-
_all_settings[var_name
|
161
|
+
_all_settings[var_name]
|
159
162
|
end
|
160
163
|
|
161
164
|
def _table_exists?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-settings-cached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
- !ruby/object:Gem::Version
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
152
|
+
rubygems_version: 3.1.4
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: The best solution for store global settings in Rails applications.
|