lib/rails-settings/base.rb in rails-settings-cached-2.0.3 vs lib/rails-settings/base.rb in rails-settings-cached-2.0.4
- old
+ new
@@ -44,15 +44,15 @@
end
private
def _define_field(key, default: nil, type: :string, readonly: false)
if readonly
- self.class.define_method(key) do
+ define_singleton_method(key) do
self.send(:_covert_string_to_typeof_value, type, default)
end
else
- self.class.define_method(key) do
+ define_singleton_method(key) do
val = self.send(:_value_of, key)
result = nil
if !val.nil?
result = val
else
@@ -63,11 +63,11 @@
result = self.send(:_covert_string_to_typeof_value, type, result)
result
end
- self.class.define_method("#{key}=") do |value|
+ define_singleton_method("#{key}=") do |value|
var_name = key.to_s
record = find_by(var: var_name) || new(var: var_name)
value = self.send(:_covert_string_to_typeof_value, type, value)
@@ -77,11 +77,11 @@
value
end
end
if type == :boolean
- self.class.define_method("#{key}?") do
+ define_singleton_method("#{key}?") do
self.send(key)
end
end
end
@@ -113,10 +113,10 @@
def rails_initialized?
Rails.application && Rails.application.initialized?
end
def _all_settings
- raise "You can use settings before Rails initialize." unless rails_initialized?
+ raise "You cannot use settings before Rails initialize." unless rails_initialized?
RequestStore.store[:rails_settings_all_settings] ||= begin
Rails.cache.fetch(self.cache_key, expires_in: 1.week) do
vars = unscoped.select("var, value")
result = {}
vars.each { |record| result[record.var] = record.value }