Class: Perus::Server::CommandConfig
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Perus::Server::CommandConfig
- Defined in:
- lib/perus/server/models/command_config.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create_with_params(params) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/perus/server/models/command_config.rb', line 50 def self.create_with_params(params) = (params) CommandConfig.create( command: params['command'], options: ) end |
.process_options(params) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/perus/server/models/command_config.rb', line 29 def self.(params) return {} if params['options'].nil? # ignore empty options (will use default) = 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..each do |option| next unless option.boolean? next unless .include?(option.name.to_s) value = [option.name.to_s] [option.name.to_s] = value == 'true' end end |
Instance Method Details
#command_class ⇒ Object
20 21 22 |
# File 'lib/perus/server/models/command_config.rb', line 20 def command_class Perus::Pinger.const_get(command) end |
#config_hash ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/perus/server/models/command_config.rb', line 7 def config_hash { id: id, type: command, options: } end |
#update_options!(params) ⇒ Object
24 25 26 27 |
# File 'lib/perus/server/models/command_config.rb', line 24 def (params) self. = self.class.(params) save end |
#validate ⇒ Object
15 16 17 18 |
# File 'lib/perus/server/models/command_config.rb', line 15 def validate super validates_presence :command end |