Extend rails-settings-cached to merge db-saved hash values with defaults
This commit is contained in:
parent
ca50ceeaf0
commit
2939e9898b
6 changed files with 44 additions and 70 deletions
9
app/lib/settings/extend.rb
Normal file
9
app/lib/settings/extend.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module Settings
|
||||
module Extend
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def settings
|
||||
ScopedSettings.for_thing(self)
|
||||
end
|
||||
end
|
||||
end
|
12
app/lib/settings/scoped_settings.rb
Normal file
12
app/lib/settings/scoped_settings.rb
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue