Class: ConcertoConfigServer
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- ConcertoConfigServer
- Defined in:
- lib/bandshell/application/app.rb
Constant Summary collapse
- CONNECTION_METHODS =
push these over to netconfig.rb? Our list of available physical-layer connection methods…
[ Bandshell::WiredConnection, Bandshell::WirelessConnection ]
- ADDRESSING_METHODS =
… and available layer-3 addressing methods.
[ Bandshell::DHCPAddressing, Bandshell::StaticAddressing ]
- LOCALHOSTS =
Hosts we allow to access configuration without authenticating.
[ IPAddress.parse("127.0.0.1"), # ipv4 IPAddress.parse("::ffff:127.0.0.1"), # ipv6-mapped ipv4 IPAddress.parse("::1") # ipv6 ]
Instance Method Summary collapse
- #active_page?(path = '') ⇒ Boolean
-
#do_assign(params, instance) ⇒ Object
Set the arguments on an instance of a given configuration class.
-
#extract_class_args(params, target_class) ⇒ Object
Extract arguments from a set of form data that are intended to go to a specific network configuration class.
-
#pick_class(name, list) ⇒ Object
Given the name of a class, pick a class out of a list of allowed classes.
- #player_info ⇒ Object
Instance Method Details
#active_page?(path = '') ⇒ Boolean
43 44 45 |
# File 'lib/bandshell/application/app.rb', line 43 def active_page?(path='') request.path_info == '/' + path end |
#do_assign(params, instance) ⇒ Object
Set the arguments on an instance of a given configuration class. This uses the safe_assign method that should be present in all configuration classes to determine which values are allowed to be passed via form fields (i.e. which ones are subject to validation)
333 334 335 336 337 338 339 340 341 |
# File 'lib/bandshell/application/app.rb', line 333 def do_assign(params, instance) safe = instance.safe_assign params.each do |param, value| if safe.include? param.intern instance.send((param + '=').intern, value) end end end |
#extract_class_args(params, target_class) ⇒ Object
Extract arguments from a set of form data that are intended to go to a specific network configuration class. These fields have names of the form ‘ClassName/field_name’; this function returns a hash in the form { ‘field_name’ => ‘value } containing the configuration arguments.
317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/bandshell/application/app.rb', line 317 def extract_class_args(params, target_class) result = { } params.each do |key, value| klass, arg = key.split('/', 2) if klass == target_class result[arg] = value end end result end |
#pick_class(name, list) ⇒ Object
Given the name of a class, pick a class out of a list of allowed classes. This is used for parsing the form input for network configuration.
309 310 311 |
# File 'lib/bandshell/application/app.rb', line 309 def pick_class(name, list) list.find { |klass| klass.basename == name } end |
#player_info ⇒ Object
47 48 49 50 |
# File 'lib/bandshell/application/app.rb', line 47 def player_info # Note: probably not thread-safe. @@player_info ||= Bandshell::PlayerInfo.new end |