From 2939e9898b1e0e7da6db802a00e594be4c85499d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 13 Jan 2017 02:42:22 +0100 Subject: Extend rails-settings-cached to merge db-saved hash values with defaults --- app/lib/settings/extend.rb | 9 +++++++++ app/lib/settings/scoped_settings.rb | 12 ++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 app/lib/settings/extend.rb create mode 100644 app/lib/settings/scoped_settings.rb (limited to 'app/lib/settings') diff --git a/app/lib/settings/extend.rb b/app/lib/settings/extend.rb new file mode 100644 index 000000000..7241a1221 --- /dev/null +++ b/app/lib/settings/extend.rb @@ -0,0 +1,9 @@ +module Settings + module Extend + extend ActiveSupport::Concern + + def settings + ScopedSettings.for_thing(self) + end + end +end \ No newline at end of file diff --git a/app/lib/settings/scoped_settings.rb b/app/lib/settings/scoped_settings.rb new file mode 100644 index 000000000..f8f22a91b --- /dev/null +++ b/app/lib/settings/scoped_settings.rb @@ -0,0 +1,12 @@ +module Settings + class ScopedSettings < ::Setting + def self.for_thing(object) + @object = object + self + end + + def self.thing_scoped + unscoped.where(thing_type: @object.class.base_class.to_s, thing_id: @object.id) + end + end +end \ No newline at end of file -- cgit