class Perus::Server::CommandConfig
Public Class Methods
create_with_params(params)
click to toggle source
# File lib/perus/server/models/command_config.rb, line 50 def self.create_with_params(params) options = process_options(params) CommandConfig.create( command: params['command'], options: options ) end
process_options(params)
click to toggle source
# File lib/perus/server/models/command_config.rb, line 29 def self.process_options(params) return {} if params['options'].nil? # ignore empty options (will use default) options = params['options'].reject do |attr, value| value.empty? end # replace 'true' and 'false' with actual boolean values # but only for boolean options command = Perus::Pinger.const_get(params['command']) command.options.each do |option| next unless option.boolean? next unless options.include?(option.name.to_s) value = options[option.name.to_s] options[option.name.to_s] = value == 'true' end options end
Public Instance Methods
command_class()
click to toggle source
# File lib/perus/server/models/command_config.rb, line 20 def command_class Perus::Pinger.const_get(command) end
config_hash()
click to toggle source
# File lib/perus/server/models/command_config.rb, line 7 def config_hash { id: id, type: command, options: options } end
update_options!(params)
click to toggle source
# File lib/perus/server/models/command_config.rb, line 24 def update_options!(params) self.options = self.class.process_options(params) save end
validate()
click to toggle source
Calls superclass method
# File lib/perus/server/models/command_config.rb, line 15 def validate super validates_presence :command end