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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc604a3e9ea5a7ed498250820ca7e93ec44e38adb88380b24b0f7b2d5dc164b8
4
- data.tar.gz: 9e62d3f49c59e981655a22924d2c32d346ba4618a6c98b4b8b1a0dfb6fd6db24
3
+ metadata.gz: 659ee746f1a087bb3ee48bba9f72a3dfd6af920830c6b003fd3bd909dce0a3c9
4
+ data.tar.gz: bb07a004ae0bbe413df58a0e2fd72fa7940cf5c55661c30214161745ebc5accc
5
5
  SHA512:
6
- metadata.gz: 7bfc23cb9fadddad15c1f3c341973bae5571cdb324ebb7d71f8c075c3877912d7f40b2792cbeaa582a79f22bcde166def831506c95d90444cd7193077492d4a7
7
- data.tar.gz: dc55136872ad58751d08f745d93a7707e3e815f6ffc99adcc5d63b19e980594a7874c11484976b7342932ca511ace408c8d48bdd5de5666854b544d908345678
6
+ metadata.gz: 2cbd53148b2110e12e8280a34691e9c08fb1e0805d2cc3ce8a4d25bbb477339e0116d508bac3bfb988bd96ffd3c173838475b5c85bb4659644b275585870198f
7
+ data.tar.gz: afe704c8920d76f70795ad55ac17a5ccbfa9807abe9903090fa797b1eb9a7ac4c5564b0a817ccca329b57704eebd3d688ad347c1f6afce58b4fbb58e20a029a1
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsSettings
4
- class Base < ActiveRecord::Base
5
- class SettingNotFound < RuntimeError; end
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)
@@ -3,7 +3,7 @@
3
3
  module RailsSettings
4
4
  class << self
5
5
  def version
6
- "2.5.3"
6
+ "2.6.0"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-settings-cached
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee