Class: ProconBypassMan::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/configuration.rb

Overview

app.rbから設定される値。プロセスを起動してから不変

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enable_critical_error_loggingObject

Returns the value of attribute enable_critical_error_logging.



57
58
59
# File 'lib/procon_bypass_man/configuration.rb', line 57

def enable_critical_error_logging
  @enable_critical_error_logging
end

#enable_home_led_on_connectBoolean

Returns default true.

Returns:

  • (Boolean)

    default true



201
202
203
204
205
206
207
# File 'lib/procon_bypass_man/configuration.rb', line 201

def enable_home_led_on_connect
  if defined?(@enable_home_led_on_connect)
    return @enable_home_led_on_connect
  else
    true
  end
end

#enable_reporting_pressed_buttons=(value) ⇒ Object (writeonly)

削除予定



61
62
63
# File 'lib/procon_bypass_man/configuration.rb', line 61

def enable_reporting_pressed_buttons=(value)
  @enable_reporting_pressed_buttons = value
end

#external_input_channelsArray<ProconBypassMan::ExternalInput::Channel::TCPIP, ProconBypassMan::ExternalInput::Channel::SerialPort>

Returns:

  • (Array<ProconBypassMan::ExternalInput::Channel::TCPIP, ProconBypassMan::ExternalInput::Channel::SerialPort>)


210
211
212
# File 'lib/procon_bypass_man/configuration.rb', line 210

def external_input_channels
  @external_input_channels || []
end

#io_monitor_logging=(value) ⇒ Object (writeonly)

NOTE 非推奨. 削除したいが設定ファイルに残っているときにエラーにしたくないので互換性維持のため残す



64
65
66
# File 'lib/procon_bypass_man/configuration.rb', line 64

def io_monitor_logging=(value)
  @io_monitor_logging = value
end

#never_exit_accidentallyBoolean

Returns default false.

Returns:

  • (Boolean)

    default false



191
192
193
# File 'lib/procon_bypass_man/configuration.rb', line 191

def never_exit_accidentally
  @never_exit_accidentally || false
end

#raw_settingObject



186
187
188
# File 'lib/procon_bypass_man/configuration.rb', line 186

def raw_setting
  @raw_setting ||= {}
end

#verbose_bypass_logObject



182
183
184
# File 'lib/procon_bypass_man/configuration.rb', line 182

def verbose_bypass_log
  @verbose_bypass_log || !!ENV["VERBOSE_BYPASS_LOG"]
end

Instance Method Details

#api_serverString, NilClass

Returns:

  • (String, NilClass)


127
128
129
# File 'lib/procon_bypass_man/configuration.rb', line 127

def api_server
  api_servers&.first
end

#api_serversArray<String>

Returns:

  • (Array<String>)


169
170
171
172
173
174
175
# File 'lib/procon_bypass_man/configuration.rb', line 169

def api_servers
  if !!ENV["API_SERVER"]
    [ENV["API_SERVER"]].reject(&:nil?)
  else
    [@api_servers].flatten.reject(&:nil?)
  end
end

#api_servers=(api_servers) ⇒ Object



92
93
94
95
# File 'lib/procon_bypass_man/configuration.rb', line 92

def api_servers=(api_servers)
  @api_servers = api_servers
  return self
end

#bypass_modeObject



88
89
90
# File 'lib/procon_bypass_man/configuration.rb', line 88

def bypass_mode
  @bypass_mode || ProconBypassMan::BypassMode.default_value
end

#bypass_mode=(value) ⇒ Object

NOTE 不具合の原因は修正済みなので可変である必要は無くなった。削除したいが各端末内の設定ファイルに存在している場合があるのでしばらく残す



81
82
83
84
85
86
# File 'lib/procon_bypass_man/configuration.rb', line 81

def bypass_mode=(value)
  @bypass_mode = ProconBypassMan::BypassMode.new(
    mode: value[:mode],
    gadget_to_procon_interval: value[:gadget_to_procon_interval],
  )
end

#current_ws_server_urlString, NilClass

Returns:

  • (String, NilClass)


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/procon_bypass_man/configuration.rb', line 132

def current_ws_server_url
  return @current_ws_server_url if defined?(@current_ws_server_url)
  return unless api_server

  response_json = ProconBypassMan::HttpClient.new(server: api_server, path: '/api/v1/configuration').get
  ws_server_url = response_json&.fetch("ws_server_url", nil)

  begin
    uri = URI.parse(ws_server_url)
    if uri.scheme == 'ws'
      @current_ws_server_url = uri.to_s
      return @current_ws_server_url
    elsif uri.scheme == 'wss' # NOTE:  SSL_CTX_use_certificate: ee key too small (OpenSSL::SSL::SSLError) が起きるので
      uri.scheme = 'ws'
      @current_ws_server_url = uri.to_s
      return @current_ws_server_url
    else
      ProconBypassMan.logger.warn { "#{ws_server_url} is invalid." }
      return nil
    end
  rescue URI::InvalidURIError => e
    ProconBypassMan.logger.warn { "#{ws_server_url} is invalid. #{e}" }
    nil
  end
end

#digest_pathObject



122
123
124
# File 'lib/procon_bypass_man/configuration.rb', line 122

def digest_path
  "#{root}/.setting_yaml_digest"
end

#enable_procon_performance_measurement?Boolean

Returns プロコンから「入力にかかっている時間」と「1秒間あたり何回入力できているか」をサーバに送信する.

Returns:

  • (Boolean)

    プロコンから「入力にかかっている時間」と「1秒間あたり何回入力できているか」をサーバに送信する



196
197
198
# File 'lib/procon_bypass_man/configuration.rb', line 196

def enable_procon_performance_measurement?
  has_api_server?
end

#enable_remote_action?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/procon_bypass_man/configuration.rb', line 164

def enable_remote_action?
  enable_ws?
end

#enable_ws?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/procon_bypass_man/configuration.rb', line 159

def enable_ws?
  !!api_server
end

#error_loggerObject



114
115
116
117
118
119
120
# File 'lib/procon_bypass_man/configuration.rb', line 114

def error_logger
  if enable_critical_error_logging
    @error_logger ||= Logger.new("#{ProconBypassMan.root}/error.log", 1, 1024 * 1024 * 1)
  else
    Logger.new(File.open("/dev/null"))
  end
end

#has_api_server?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/procon_bypass_man/configuration.rb', line 178

def has_api_server?
  !!api_server
end

#loggerObject



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/procon_bypass_man/configuration.rb', line 102

def logger
  if ENV["PBM_ENV"] == 'test'
    return Logger.new($stdout)
  end

  if defined?(@logger) && @logger.is_a?(Logger)
    @logger
  else
    Logger.new(File.open("/dev/null"))
  end
end

#logger=(logger) ⇒ Object



97
98
99
100
# File 'lib/procon_bypass_man/configuration.rb', line 97

def logger=(logger)
  @logger = logger
  return self
end

#rootObject



71
72
73
74
75
76
77
78
# File 'lib/procon_bypass_man/configuration.rb', line 71

def root
  if defined?(@root)
    @root
  else
    ProconBypassMan.logger.warn 'root pathが未設定です'
    File.expand_path('..', __dir__ || ".").freeze
  end
end

#root=(path) ⇒ Object



66
67
68
69
# File 'lib/procon_bypass_man/configuration.rb', line 66

def root=(path)
  @root = path
  return self
end