* Update annotate to version 2.7.3 * Update aws-sdk-s3 to version 1.9.2 * Update browser to version 2.5.3 * Update capistrano to version 3.10.2 * Update domain_name to version 0.5.20180417 * Update http to version 3.2.0 * Update lograge to version 0.10.0 * Update oj to version 3.5.1 * Update parallel_tests to version 2.21.3 * Update puma to version 3.11.4 * Update rubocop to version 0.55.0 * Update scss_lint to version 0.57.0 * Update simplecov to version 0.16.1 * Update tty-command to version 0.8.0 * Update tty-prompt to version 0.16.0 * Update pkg-config to version 1.3.0 * Update fog-local to version 0.5.0 * Update fog-openstack to version 0.1.25 * Update devise-two-factor to version 3.0.3 * bundle update
		
			
				
	
	
		
			58 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # frozen_string_literal: true
 | |
| # == Schema Information
 | |
| #
 | |
| # Table name: settings
 | |
| #
 | |
| #  id         :bigint(8)        not null, primary key
 | |
| #  var        :string           not null
 | |
| #  value      :text
 | |
| #  thing_type :string
 | |
| #  created_at :datetime
 | |
| #  updated_at :datetime
 | |
| #  thing_id   :bigint(8)
 | |
| #
 | |
| 
 | |
| class Setting < RailsSettings::Base
 | |
|   source Rails.root.join('config', 'settings.yml')
 | |
| 
 | |
|   def to_param
 | |
|     var
 | |
|   end
 | |
| 
 | |
|   class << self
 | |
|     def [](key)
 | |
|       return super(key) unless rails_initialized?
 | |
| 
 | |
|       val = Rails.cache.fetch(cache_key(key, nil)) do
 | |
|         db_val = object(key)
 | |
| 
 | |
|         if db_val
 | |
|           default_value = default_settings[key]
 | |
| 
 | |
|           return default_value.with_indifferent_access.merge!(db_val.value) if default_value.is_a?(Hash)
 | |
|           db_val.value
 | |
|         else
 | |
|           default_settings[key]
 | |
|         end
 | |
|       end
 | |
|       val
 | |
|     end
 | |
| 
 | |
|     def all_as_records
 | |
|       vars    = thing_scoped
 | |
|       records = vars.map { |r| [r.var, r] }.to_h
 | |
| 
 | |
|       default_settings.each do |key, default_value|
 | |
|         next if records.key?(key) || default_value.is_a?(Hash)
 | |
|         records[key] = Setting.new(var: key, value: default_value)
 | |
|       end
 | |
| 
 | |
|       records
 | |
|     end
 | |
| 
 | |
|     def default_settings
 | |
|       return {} unless RailsSettings::Default.enabled?
 | |
|       RailsSettings::Default.instance
 | |
|     end
 | |
|   end
 | |
| end
 |