# frozen_string_literal: true require 'forwardable' require_relative './config/builder' require_relative './config/constants' require_relative './config/data' require_relative './config/option_validator' # Generate blog post/article fixture data, with embedded marker tag pairs. module ArticleFixtureGen # Maintain configuration information for app. class Config # Error raised when validating one or more attributes fails. class ValidationError < RuntimeError end # class ArticleFixtureGen::Config::ValidationError extend Forwardable def initialize(options_hash) data = Builder.call(options_hash) validate(data) # will raise if not valid @values = Data.new data self end def self.defaults new Constants::DEFAULTS end def_delegators :@values, :article_count, :config, :config_given, :generate_config, :generate_config_given, :para_count_max, :para_count_min, :pmtp_count, :pmtp_text, :sent_count_max, :sent_count_min, :smtp_count, :smtp_text, :to_hash private def validate(data) errors = OptionValidator.call options: data return self if errors.empty? raise ValidationError, errors.first end end # class ArticleFixtureGen::Config end