10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/procon_bypass_man/buttons_setting_configuration/loader.rb', line 10
def self.load(setting_path: )
metadata_loader = ProconBypassMan::ButtonsSettingConfiguration::MetadataLoader.load(setting_path: setting_path)
if(Gem::Version.new(metadata_loader.required_pbm_version) >= Gem::Version.new(ProconBypassMan::VERSION))
ProconBypassMan::SendErrorCommand.execute(error: '起動中のPBMが設定ファイルのバージョンを満たしていません。設定ファイルが意図した通り動かない可能性があります。PBMのバージョンをあげてください。')
end
ProconBypassMan::Procon.reset!
new_instance, yaml =
begin
new_instance = ProconBypassMan::ButtonsSettingConfiguration.new
new_instance.setting_path = setting_path
yaml = ProconBypassMan::YamlLoader.load(path: setting_path)
new_instance.instance_eval(yaml["setting"])
validator = Validator.new(new_instance)
if validator.valid?
[new_instance, yaml]
else
fallback_setting_if_has_backup(current_setting_path: setting_path)
raise ProconBypassMan::CouldNotLoadConfigError, validator.errors_to_s
end
rescue SyntaxError
fallback_setting_if_has_backup(current_setting_path: setting_path)
raise ProconBypassMan::CouldNotLoadConfigError, "Rubyスクリプトのシンタックスエラーです"
rescue NameError
fallback_setting_if_has_backup(current_setting_path: setting_path)
raise ProconBypassMan::CouldNotLoadConfigError, "Rubyスクリプトに未定義の定数・変数があります"
rescue Psych::SyntaxError
fallback_setting_if_has_backup(current_setting_path: setting_path)
raise ProconBypassMan::CouldNotLoadConfigError, "yamlのシンタックスエラーです"
end
ProconBypassMan.config.raw_setting = yaml
ProconBypassMan.buttons_setting_configuration = new_instance
File.write(ProconBypassMan.digest_path, Digest::MD5.hexdigest(yaml["setting"]))
FileUtils.rm_rf(ProconBypassMan.fallback_setting_path)
ProconBypassMan.buttons_setting_configuration
end
|