class Queuel::Configurator
Constants
- InvalidConfigurationError
Attributes
option_values[RW]
Private Class Methods
define_param_accessors(param_name, boolean = false)
click to toggle source
# File lib/queuel/configurator.rb, line 12 def self.define_param_accessors(param_name, boolean = false) define_method param_name do |*values| value = values.first value ? self.send("#{param_name}=", value) : retrieve(param_name) end define_method("#{param_name}?") { !!retrieve(param_name) } if boolean define_method "#{param_name}=" do |value| validate!(param_name, value) && instance_variable_set("@#{param_name}", value) end end
option_values()
click to toggle source
# File lib/queuel/configurator.rb, line 8 def self.option_values @option_values ||= {} end
param(param_name, options = {})
click to toggle source
# File lib/queuel/configurator.rb, line 43 def self.param(param_name, options = {}) attr_accessor param_name self.option_values[param_name] = options define_param_accessors param_name, options[:boolean] public param_name public "#{param_name}=" end
Private Instance Methods
retrieve(param)
click to toggle source
# File lib/queuel/configurator.rb, line 35 def retrieve(param) if instance_variable_defined?("@#{param}") instance_variable_get("@#{param}") else self.class.option_values[param][:default] end end
validate(param_name, value)
click to toggle source
# File lib/queuel/configurator.rb, line 24 def validate(param_name, value) validator = self.class.option_values[param_name].fetch(:validate) { {} }[:validator] || ->(val) { true } validator.call value end
validate!(param_name, value)
click to toggle source
# File lib/queuel/configurator.rb, line 29 def validate!(param_name, value) message = self.class.option_values[param_name].fetch(:validate) { {} }[:message] message ||= "#{value} is not a valid value for #{param_name}" validate(param_name, value) || raise(InvalidConfigurationError, message) end