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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29703d30ef00244c99b49047ce3a05edd212ee71a23433cb581d5bf69c6a02c6
4
- data.tar.gz: 7f1d2dffdf1c552faca1b7afdbaaeaa52039897afb5364b8aef37de3d93389c4
3
+ metadata.gz: 3e423b44c4e49c3d0ffb953ffee50e1b268262a770eba8a9114b23c494458861
4
+ data.tar.gz: d5997e14e9288ec4c0fdf858a1029ea3a379b1e1aecf05b2ed8bb9158bf45bbb
5
5
  SHA512:
6
- metadata.gz: 6e1b41ac975dd31fadf90c5d9c059542aaeb09a0bfbf3f137266a32ae58c30557afedbe33c775af9a2683a8f8b56b85ee0f94b4a063a27e5c79176b5c1714d0d
7
- data.tar.gz: a5ee74e8dd391aab429db68904b5d78a79581fd41de6304aece887fcdf9be8b023f4fff03a2fedbfdbc81cff964be5b695a90c5e4c3f908d49bed01c0fb70f83
6
+ metadata.gz: edf9eff836688ce1f82d3de681c34a7fd9c782e526e952ac42430d7f559b7aae51c3f73f4a749f167302f31b4b3286dce2d5f21dc504a6735981db6a0d259b6f
7
+ data.tar.gz: dfcbf34fcbb3f0af4d0161601537db441c8d07632ffc2b964857b10fcaa6af8b88f2cbd2c758d21bf3e9676a7dc8a1ea607230c3e06560fcf65feef2c7fff434
@@ -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], separator: opts[:separator], validates: opts[:validates])
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.to_s,
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.to_s
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] = Proc.new { |item| item.var.to_s == key.to_s }
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
- value == "true" || value == "1" || value == 1 || value == true
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
- begin
131
- YAML.load(value).to_h
132
- rescue StandardError
133
- eval(value).to_h
134
- end
135
- rescue StandardError
136
- {}
137
- end
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.to_s]
161
+ _all_settings[var_name]
159
162
  end
160
163
 
161
164
  def _table_exists?
@@ -3,7 +3,7 @@
3
3
  module RailsSettings
4
4
  class << self
5
5
  def version
6
- "2.5.1"
6
+ "2.5.2"
7
7
  end
8
8
  end
9
9
  end
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.1
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-09 00:00:00.000000000 Z
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.2.0
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.