2019-05-09 23:10:02 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-23 21:19:08 +08:00
|
|
|
class Settings < ApplicationRecord
|
2023-09-08 20:42:20 +08:00
|
|
|
attr_accessor :merged_values
|
|
|
|
|
|
|
|
before_validation -> { self.values = merged_values || values }
|
|
|
|
|
2017-02-21 20:07:10 +08:00
|
|
|
def self.instance
|
2022-05-26 19:27:18 +08:00
|
|
|
first || new
|
2017-02-21 20:07:10 +08:00
|
|
|
end
|
2023-08-01 16:44:27 +08:00
|
|
|
|
|
|
|
def values
|
2023-09-08 20:42:20 +08:00
|
|
|
self.merged_values ||= super
|
2023-08-01 16:44:27 +08:00
|
|
|
self.class.instance_methods(false).grep(/^load_values_from_[A-Z0-9_]*/).each do |method|
|
2023-09-08 20:42:20 +08:00
|
|
|
self.merged_values = self.merged_values.merge(public_send(method))
|
2023-08-01 16:44:27 +08:00
|
|
|
end
|
|
|
|
merged_values
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_values_from_env
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
2017-02-17 23:49:56 +08:00
|
|
|
end
|