# frozen_string_literal: true # Generate blog post/article fixture data, with embedded marker tag pairs. module ArticleFixtureGen # Maintain configuration information for app. class Config # Encapsulates validations of configuration option values. class OptionValidator def self.call(options:) OptionValidator.new.call(options) end def initialize @errors = [] self end def call(options) @options = options FATALS.each { |entry| validate_option entry } errors end private attr_reader :errors, :options FATALS = [ { key: :para_count_max, message: 'must be at least 1', cond: -> (opts) { opts[:para_count_max] < 1 } }, { key: :para_count_max, message: 'must be >= the value for --para_count_min', cond: -> (opts) { opts[:para_count_max] < opts[:para_count_min] } }, { key: :para_count_min, message: 'must be at least 1', cond: -> (opts) { opts[:para_count_min] < 1 } }, { key: :para_count_min, message: 'must be <= the value for --para_count_max', cond: -> (opts) { opts[:para_count_min] > opts[:para_count_max] } }, { key: :pmtp_count, message: 'must be at least 0', cond: -> (opts) { (opts[:pmtp_count]).negative? } }, { key: :pmtp_text, message: 'may not be empty', cond: -> (opts) { opts[:pmtp_text].to_s.strip.empty? } }, { key: :sent_count_max, message: 'must be at least 1', cond: -> (opts) { opts[:sent_count_max] < 1 } }, { key: :sent_count_max, message: 'must be >= the value for --sent_count_min', cond: -> (opts) { opts[:sent_count_max] < opts[:sent_count_min] } }, { key: :sent_count_min, message: 'must be at least 1', cond: -> (opts) { opts[:sent_count_min] < 1 } }, { key: :sent_count_min, message: 'must be <= the value for --sent_count_max', cond: -> (opts) { opts[:sent_count_min] > opts[:sent_count_max] } }, { key: :smtp_count, message: 'must be at least 0', cond: -> (opts) { (opts[:smtp_count]).negative? } }, { key: :smtp_text, message: 'may not be empty', cond: -> (opts) { opts[:smtp_text].to_s.strip.empty? } } ].freeze private_constant :FATALS def fails?(entry) entry[:cond].call(options) end # Reek and hashes = :reek:FeatureEnvy; aka petrol and flame. FIXME def report_failure(entry) @errors << [entry[:key], entry[:message]] end def validate_option(entry) report_failure(entry) if fails?(entry) end end # class ArticleFixtureGen::Config::OptionValidator end # class ArticleFixtureGen::Config end