]> cat aescling's git repositories - mastodon.git/blob - app/models/setting.rb
Bump aws-sdk-s3 from 1.89.0 to 1.91.0 (#15879)
[mastodon.git] / app / models / setting.rb
1 # frozen_string_literal: true
2 # == Schema Information
3 #
4 # Table name: settings
5 #
6 # id :bigint(8) not null, primary key
7 # var :string not null
8 # value :text
9 # thing_type :string
10 # created_at :datetime
11 # updated_at :datetime
12 # thing_id :bigint(8)
13 #
14
15 class Setting < RailsSettings::Base
16 source Rails.root.join('config', 'settings.yml')
17
18 def to_param
19 var
20 end
21
22 class << self
23 def [](key)
24 return super(key) unless rails_initialized?
25
26 val = Rails.cache.fetch(cache_key(key, nil)) do
27 db_val = object(key)
28
29 if db_val
30 default_value = default_settings[key]
31
32 return default_value.with_indifferent_access.merge!(db_val.value) if default_value.is_a?(Hash)
33 db_val.value
34 else
35 default_settings[key]
36 end
37 end
38 val
39 end
40
41 def all_as_records
42 vars = thing_scoped
43 records = vars.index_by(&:var)
44
45 default_settings.each do |key, default_value|
46 next if records.key?(key) || default_value.is_a?(Hash)
47 records[key] = Setting.new(var: key, value: default_value)
48 end
49
50 records
51 end
52
53 def default_settings
54 return {} unless RailsSettings::Default.enabled?
55 RailsSettings::Default.instance
56 end
57 end
58 end
This page took 0.08297 seconds and 4 git commands to generate.