Sha256: ee5a85054b6d14ee3ce5257806b87d7ec845e7d3ea12f4bcee2da58537d9c807
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
module CandyCheck module Utils # Very basic base implementation to store and validate a configuration class Config # Initializes a new configuration from a hash # @param attributes [Hash] def initialize(attributes) attributes.each do |k, v| instance_variable_set "@#{k}", v end if attributes.is_a? Hash validate! end protected # Hook to check for validation error in the sub classes # should raise an error if not passed def validate! # pass end # Check for the presence of an attribute # @param name [String] # @raise [ArgumentError] if attribute is missing def validates_presence(name) return if send(name) raise ArgumentError, "Configuration field #{name} is missing" end # Checks for the inclusion of an attribute # @param name [String] # @param values [Array] of possible values def validates_inclusion(name, *values) return if values.include?(send(name)) raise ArgumentError, "Configuration field #{name} should be "\ "one of: #{values.join(', ')}" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
candy_check-0.1.0.pre | lib/candy_check/utils/config.rb |
candy_check-0.0.5 | lib/candy_check/utils/config.rb |