* Change: #532 ElasticSearch設定の外出し * バージョンチェック * 起動時にエラー
This commit is contained in:
parent
8e7c66522e
commit
a8fbcb3fb6
9 changed files with 508 additions and 269 deletions
60
app/lib/chewy_config.rb
Normal file
60
app/lib/chewy_config.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'singleton'
|
||||
require 'yaml'
|
||||
|
||||
class ChewyConfig
|
||||
include Singleton
|
||||
|
||||
class InvalidElasticSearchVersionError < Mastodon::Error; end
|
||||
|
||||
CONFIG_VERSION = 1
|
||||
|
||||
def initialize
|
||||
custom_config_file = Rails.root.join('.elasticsearch.yml')
|
||||
default_config_file = Rails.root.join('config', 'elasticsearch.default.yml')
|
||||
|
||||
custom_config = nil
|
||||
custom_config = YAML.load_file(custom_config_file) if File.exist?(custom_config_file)
|
||||
default_config = YAML.load_file(default_config_file)
|
||||
|
||||
@config = default_config.merge(custom_config || {})
|
||||
@config = @config.merge(YAML.load_file(Rails.root.join('config', 'elasticsearch.default-ja-sudachi.yml'))) if Rails.env.test?
|
||||
|
||||
raise InvalidElasticSearchVersionError, "ElasticSearch config version is missmatch. expected version=#{CONFIG_VERSION} actual version=#{@config['version']}" if @config['version'] != CONFIG_VERSION
|
||||
end
|
||||
|
||||
attr_reader :config
|
||||
|
||||
def accounts
|
||||
config['accounts']
|
||||
end
|
||||
|
||||
def accounts_analyzers
|
||||
config['accounts_analyzers']
|
||||
end
|
||||
|
||||
def public_statuses
|
||||
config['public_statuses']
|
||||
end
|
||||
|
||||
def public_statuses_analyzers
|
||||
config['public_statuses_analyzers']
|
||||
end
|
||||
|
||||
def statuses
|
||||
config['statuses']
|
||||
end
|
||||
|
||||
def statuses_analyzers
|
||||
config['statuses_analyzers']
|
||||
end
|
||||
|
||||
def tags
|
||||
config['tags']
|
||||
end
|
||||
|
||||
def tags_analyzers
|
||||
config['tags_analyzers']
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue