Sha256: 650b5f9b0ce322bc71c2febb9930340b3a1ffb1698ebabe59851ca434c5aef74

Contents?: true

Size: 1.44 KB

Versions: 27

Compression:

Stored size: 1.44 KB

Contents

require "i18n"
require "pact_broker/api/pact_broker_urls"

I18n.config.load_path << File.expand_path("../locale/en.yml", __FILE__)

module PactBroker
  # Provides an interface to the I18n library specifically for
  # the PactBroker's messages.
  module Messages

    extend self

    # Interpolates an internationalized string.
    # @param [String] key the name of the string to interpolate
    # @param [Hash] options options to pass to I18n, including
    #   variables to interpolate.
    # @return [String] the interpolated string
    def message(key, options={})
      ::I18n.t(key, { :scope => :pact_broker }.merge(options))
    end

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

    def potential_duplicate_pacticipant_message new_name, potential_duplicate_pacticipants, base_url
      existing_names = potential_duplicate_pacticipants.
        collect{ | p | "* #{p.name}"  }.join("\n")
      message("errors.duplicate_pacticipant",
        new_name: new_name,
        existing_names: existing_names,
        create_pacticipant_url: pacticipants_url(base_url))
    end

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

    private

    def pacticipants_url base_url
      PactBroker::Api::PactBrokerUrls.pacticipants_url base_url
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
pact_broker-2.99.0 lib/pact_broker/messages.rb
pact_broker-2.98.0 lib/pact_broker/messages.rb
pact_broker-2.97.0 lib/pact_broker/messages.rb
pact_broker-2.96.0 lib/pact_broker/messages.rb
pact_broker-2.95.1 lib/pact_broker/messages.rb
pact_broker-2.95.0 lib/pact_broker/messages.rb
pact_broker-2.94.0 lib/pact_broker/messages.rb
pact_broker-2.93.4 lib/pact_broker/messages.rb
pact_broker-2.93.3 lib/pact_broker/messages.rb
pact_broker-2.93.2 lib/pact_broker/messages.rb
pact_broker-2.93.1 lib/pact_broker/messages.rb
pact_broker-2.93.0 lib/pact_broker/messages.rb
pact_broker-2.92.0 lib/pact_broker/messages.rb
pact_broker-2.91.0 lib/pact_broker/messages.rb
pact_broker-2.90.0 lib/pact_broker/messages.rb
pact_broker-2.89.1 lib/pact_broker/messages.rb
pact_broker-2.89.0 lib/pact_broker/messages.rb
pact_broker-2.88.0 lib/pact_broker/messages.rb
pact_broker-2.87.0 lib/pact_broker/messages.rb
pact_broker-2.86.0 lib/pact_broker/messages.rb