Module: Ibex::Codegen::RubyErrorMessages

Included in:
Ruby
Defined in:
lib/ibex/codegen/ruby_error_messages.rb,
sig/ibex/codegen/ruby_error_messages.rbs

Overview

Serializes immutable example-keyed error records into generated Ruby.

Instance Method Summary collapse

Instance Method Details

#error_message_literal(message) ⇒ String

RBS:

  • (String | { id: String, message: String } message) -> String

Parameters:

  • message (String, { id: String, message: String })

Returns:

  • (String)


19
20
21
22
23
24
25
# File 'lib/ibex/codegen/ruby_error_messages.rb', line 19

def error_message_literal(message)
  return message.inspect unless message.is_a?(Hash)

  error_id = message.fetch(:id)
  text = message.fetch(:message)
  "{ id: #{error_id.inspect}, message: #{text.inspect} }.freeze"
end

#error_messages_literalString

RBS:

  • () -> String

Returns:

  • (String)


10
11
12
13
14
15
16
# File 'lib/ibex/codegen/ruby_error_messages.rb', line 10

def error_messages_literal
  # @type self: Ruby
  return "{}" if @error_messages.empty?

  entries = @error_messages.map { |state, message| "#{state} => #{error_message_literal(message)}" }
  "{ #{entries.join(', ')} }"
end