Sha256: c8adfa1238449353b02d76782de4e5bdad8d484815a965eea1073c7e0cb2909c

Contents?: true

Size: 716 Bytes

Versions: 1

Compression:

Stored size: 716 Bytes

Contents

# frozen_string_literal: true

require 'erb'
require 'ostruct'

module Masking
  class Cli
    class ErrorMessage
      def initialize(error_class)
        @error_class = error_class
      end

      def message(**keyword_args)
        error_message(keyword_args)
      end

      private

      attr_reader :error_class

      YAML_FILE_PATH = Pathname('lib/masking/cli/error_messages.yml')

      def error_messages
        @error_messages = YAML.safe_load(YAML_FILE_PATH.read)
      end

      def error_message(keyword_args)
        ERB.new(
          error_messages.fetch(error_class.to_s)
        ).result(
          OpenStruct.new(keyword_args).instance_eval { binding }
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
masking-0.0.1 lib/masking/cli/error_message.rb