module WRKFLO::Configurable
Public Class Methods
included(base)
click to toggle source
# File lib/wrkflo/configurable.rb, line 15 def self.included base base.extend ClassMethods end
Public Instance Methods
apply_configuration(raw_config)
click to toggle source
# File lib/wrkflo/configurable.rb, line 20 def apply_configuration raw_config final_config = self.class.properties.each.with_object({}) do |(name, prop), h| provided_value = raw_config[name.to_s] # Determine the real value based on the property's definition real_value = prop.resolve_value(provided_value) # Remember the real value in the actual configuration h[name.to_sym] = real_value end # Create a struct from the configuration hash to enable dot-access. @configuration = Struct.new(*final_config.keys).new(*final_config.values) end
config()
click to toggle source
# File lib/wrkflo/configurable.rb, line 52 def config @configuration end
validate_configuration() { |f| ... }
click to toggle source
Returns `true` if the configuration is valid. Otherwise, returns a pair of the property and a reason. If a block is given, this pair is also passed to the block.
# File lib/wrkflo/configurable.rb, line 36 def validate_configuration self.class.properties.values.each do |prop| if prop.required? unless config.respond_to?(prop.name) return [prop, nil, :required].tap{ |f| yield f if block_given? } end end value = config.send(prop.name) return [prop, value, :type].tap{ |f| yield f if block_given? } unless prop.matches_type?(value) end return true end