rails-settings-cached 2.5.2 → 2.5.3

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: 3e423b44c4e49c3d0ffb953ffee50e1b268262a770eba8a9114b23c494458861
4
- data.tar.gz: d5997e14e9288ec4c0fdf858a1029ea3a379b1e1aecf05b2ed8bb9158bf45bbb
3
+ metadata.gz: fc604a3e9ea5a7ed498250820ca7e93ec44e38adb88380b24b0f7b2d5dc164b8
4
+ data.tar.gz: 9e62d3f49c59e981655a22924d2c32d346ba4618a6c98b4b8b1a0dfb6fd6db24
5
5
  SHA512:
6
- metadata.gz: edf9eff836688ce1f82d3de681c34a7fd9c782e526e952ac42430d7f559b7aae51c3f73f4a749f167302f31b4b3286dce2d5f21dc504a6735981db6a0d259b6f
7
- data.tar.gz: dfcbf34fcbb3f0af4d0161601537db441c8d07632ffc2b964857b10fcaa6af8b88f2cbd2c758d21bf3e9676a7dc8a1ea607230c3e06560fcf65feef2c7fff434
6
+ metadata.gz: 7bfc23cb9fadddad15c1f3c341973bae5571cdb324ebb7d71f8c075c3877912d7f40b2792cbeaa582a79f22bcde166def831506c95d90444cd7193077492d4a7
7
+ data.tar.gz: dc55136872ad58751d08f745d93a7707e3e815f6ffc99adcc5d63b19e980594a7874c11484976b7342932ca511ace408c8d48bdd5de5666854b544d908345678
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  The best solution for store global settings in Rails applications.
4
4
 
5
- This gem will managing a table of а global key, value pairs easy. Think of it like a global Hash stored in your database, that uses simple ActiveRecord like methods for manipulation. Keep track of any global setting that you don't want to hard code into your rails app.
5
+ This gem will make managing a table of а global key, value pairs easy. Think of it like a global Hash stored in your database, that uses simple ActiveRecord like methods for manipulation. Keep track of any global setting that you don't want to hard code into your rails app.
6
6
 
7
7
  You can store any kind of object. Strings, numbers, arrays, booleans, or any object.
8
8
 
9
- [![Gem Version](https://badge.fury.io/rb/rails-settings-cached.svg)](https://rubygems.org/gems/rails-settings-cached) [![CI Status](https://travis-ci.org/huacnlee/rails-settings-cached.svg)](http://travis-ci.org/huacnlee/rails-settings-cached) [![codecov.io](https://codecov.io/github/huacnlee/rails-settings-cached/coverage.svg?branch=master)](https://codecov.io/github/huacnlee/rails-settings-cached?branch=master)
9
+ [![Gem Version](https://badge.fury.io/rb/rails-settings-cached.svg)](https://rubygems.org/gems/rails-settings-cached) [![build](https://github.com/huacnlee/rails-settings-cached/workflows/build/badge.svg)](https://github.com/huacnlee/rails-settings-cached/actions?query=workflow%3Abuild) [![codecov.io](https://codecov.io/github/huacnlee/rails-settings-cached/coverage.svg?branch=master)](https://codecov.io/github/huacnlee/rails-settings-cached?branch=master)
10
10
 
11
11
  ## Installation
12
12
 
@@ -425,6 +425,7 @@ end
425
425
  - [huacnlee/bluedoc](https://github.com/huacnlee/bluedoc) - 2.x
426
426
  - [getzealot/zealot](https://github.com/getzealot/zealot) - 2.x
427
427
  - [kaishuu0123/rebacklogs](https://github.com/kaishuu0123/rebacklogs) - 2.x
428
+ - [texterify/texterify](https://github.com/texterify/texterify) - 2.x
428
429
  - [tootsuite/mastodon](https://github.com/tootsuite/mastodon) - 0.6.x
429
430
  - [helpyio/helpy](https://github.com/helpyio/helpy) - 0.5.x
430
431
  - [daqing/rabel](https://github.com/daqing/rabel) - 0.4.x
@@ -4,11 +4,12 @@ module RailsSettings
4
4
  class Base < ActiveRecord::Base
5
5
  class SettingNotFound < RuntimeError; end
6
6
 
7
- SEPARATOR_REGEXP = /[\n,;]+/.freeze
7
+ SEPARATOR_REGEXP = /[\n,;]+/
8
8
  self.table_name = table_name_prefix + "settings"
9
9
 
10
10
  # get the value field, YAML decoded
11
11
  def value
12
+ # rubocop:disable Security/YAMLLoad
12
13
  YAML.load(self[:value]) if self[:value].present?
13
14
  end
14
15
 
@@ -73,7 +74,8 @@ module RailsSettings
73
74
 
74
75
  if readonly
75
76
  define_singleton_method(key) do
76
- send(:_convert_string_to_typeof_value, type, default, separator: separator)
77
+ result = default.is_a?(Proc) ? default.call : default
78
+ send(:_convert_string_to_typeof_value, type, result, separator: separator)
77
79
  end
78
80
  else
79
81
  define_singleton_method(key) do
@@ -130,12 +132,8 @@ module RailsSettings
130
132
  value.split(separator || SEPARATOR_REGEXP).reject { |str| str.empty? }.map(&:strip)
131
133
  when :hash
132
134
  value = begin
133
- begin
134
- YAML.load(value).to_h
135
- rescue StandardError
136
- eval(value).to_h
137
- end
138
- rescue StandardError
135
+ YAML.safe_load(value).to_h
136
+ rescue
139
137
  {}
140
138
  end
141
139
  value.deep_stringify_keys!
@@ -163,7 +161,7 @@ module RailsSettings
163
161
 
164
162
  def _table_exists?
165
163
  table_exists?
166
- rescue => e
164
+ rescue
167
165
  false
168
166
  end
169
167
 
@@ -172,13 +170,11 @@ module RailsSettings
172
170
  end
173
171
 
174
172
  def _all_settings
175
- RequestCache.settings ||= begin
176
- Rails.cache.fetch(cache_key, expires_in: 1.week) do
177
- vars = unscoped.select("var, value")
178
- result = {}
179
- vars.each { |record| result[record.var] = record.value }
180
- result.with_indifferent_access
181
- end
173
+ RequestCache.settings ||= Rails.cache.fetch(cache_key, expires_in: 1.week) do
174
+ vars = unscoped.select("var, value")
175
+ result = {}
176
+ vars.each { |record| result[record.var] = record.value }
177
+ result.with_indifferent_access
182
178
  end
183
179
  end
184
180
  end
@@ -3,7 +3,7 @@
3
3
  module RailsSettings
4
4
  class Railtie < Rails::Railtie
5
5
  initializer "rails_settings.active_record.initialization" do
6
- RailsSettings::Base.after_commit :clear_cache, on: %i(create update destroy)
6
+ RailsSettings::Base.after_commit :clear_cache, on: %i[create update destroy]
7
7
  end
8
8
  end
9
9
  end
@@ -1,9 +1,9 @@
1
1
  module RailsSettings
2
- if defined? ActiveSupport::CurrentAttributes
2
+ if defined? ActiveSupport::CurrentAttributes
3
3
  # For storage all settings in Current, it will reset after per request completed.
4
4
  # Base on ActiveSupport::CurrentAttributes
5
5
  # https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html
6
- class RequestCache < ActiveSupport::CurrentAttributes
6
+ class RequestCache < ActiveSupport::CurrentAttributes
7
7
  attribute :settings
8
8
  end
9
9
  else
@@ -27,4 +27,4 @@ module RailsSettings
27
27
  end
28
28
  end
29
29
  end
30
- end
30
+ end
@@ -3,7 +3,7 @@
3
3
  module RailsSettings
4
4
  class << self
5
5
  def version
6
- "2.5.2"
6
+ "2.5.3"
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.2
4
+ version: 2.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-21 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -110,7 +110,7 @@ dependencies:
110
110
  version: '0'
111
111
  description: "\n The best solution for store global settings in Rails applications.\n\n
112
112
  \ This gem will managing a table of а global key, value pairs easy. Think of it
113
- like a \n global Hash stored in your database, that uses simple ActiveRecord like
113
+ like a\n global Hash stored in your database, that uses simple ActiveRecord like
114
114
  methods for manipulation.\n\n Keep track of any global setting that you dont want
115
115
  to hard code into your rails app.\n You can store any kind of object. Strings,
116
116
  numbers, arrays, or any object.\n "
@@ -134,7 +134,7 @@ homepage: https://github.com/huacnlee/rails-settings-cached
134
134
  licenses:
135
135
  - MIT
136
136
  metadata: {}
137
- post_install_message:
137
+ post_install_message:
138
138
  rdoc_options: []
139
139
  require_paths:
140
140
  - lib
@@ -149,8 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  requirements: []
152
- rubygems_version: 3.1.4
153
- signing_key:
152
+ rubygems_version: 3.2.3
153
+ signing_key:
154
154
  specification_version: 4
155
155
  summary: The best solution for store global settings in Rails applications.
156
156
  test_files: []