scinote-web/app/models/concerns/settings_model.rb
2017-08-10 11:30:57 +02:00

22 lines
427 B
Ruby

module SettingsModel
extend ActiveSupport::Concern
@@default_settings = HashWithIndifferentAccess.new
included do
serialize :settings, JsonbHashSerializer
after_initialize :init_default_settings, if: :new_record?
end
class_methods do
def default_settings(dfs)
@@default_settings.merge!(dfs)
end
end
protected
def init_default_settings
self.settings = @@default_settings
end
end