Module: PactBroker::Messages

Overview

Provides an interface to the I18n library specifically for the PactBroker’s messages.

Instance Method Summary collapse

Instance Method Details

#message(key, options = {}) ⇒ String

Interpolates an internationalized string.

Parameters:

  • key (String)

    the name of the string to interpolate

  • options (Hash) (defaults to: {})

    options to pass to I18n, including variables to interpolate.

Returns:

  • (String)

    the interpolated string



18
19
20
# File 'lib/pact_broker/messages.rb', line 18

def message(key, options={})
  ::I18n.t(key, **{ :scope => :pact_broker }.merge(options))
end

#pluralize(word, count) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pact_broker/messages.rb', line 30

def pluralize(word, count)
  if count == 1
    word
  else
    if word.end_with?("y")
      word.chomp("y") + "ies"
    else
      word + "s"
    end
  end
end

#validation_message(key, options = {}) ⇒ Object



22
23
24
# File 'lib/pact_broker/messages.rb', line 22

def validation_message key, options = {}
  message("errors.validation." + key, options)
end

#validation_message_at_index(key, index, options = {}) ⇒ Object



26
27
28
# File 'lib/pact_broker/messages.rb', line 26

def validation_message_at_index key, index, options = {}
  message("errors.validation." + key, options).chomp(".") + " (at index #{index})"
end