about summary refs log tree commit diff
path: root/app/lib/settings
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-01-13 02:42:22 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-01-13 02:42:22 +0100
commit2939e9898b1e0e7da6db802a00e594be4c85499d (patch)
tree17f57c3ca48df41c8460336bc225149030c45756 /app/lib/settings
parentca50ceeaf0e4195cf8a80da9fd226d97dbe14b7c (diff)
Extend rails-settings-cached to merge db-saved hash values with defaults
Diffstat (limited to 'app/lib/settings')
-rw-r--r--app/lib/settings/extend.rb9
-rw-r--r--app/lib/settings/scoped_settings.rb12
2 files changed, 21 insertions, 0 deletions
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