Sha256: 15ad2fd9da1f43801ccbbcf27941b7456fd1dc0badd830d9895c1ed4d1decd3b

Contents?: true

Size: 432 Bytes

Versions: 5

Compression:

Stored size: 432 Bytes

Contents

module Vidar
  class Interpolation
    INTERPOLATION_PATTERN = /\{\{(\w+)\}\}/.freeze

    class << self
      def call(string, getter)
        return unless string
        fail ArgumentError, "getter must respond_to get." unless getter.respond_to?(:get)

        string.gsub(INTERPOLATION_PATTERN) do |match|
          getter.get($1) || ENV[$1] || match # rubocop:disable Style/PerlBackrefs
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vidar-1.4.0 lib/vidar/interpolation.rb
vidar-1.3.2 lib/vidar/interpolation.rb
vidar-1.3.1 lib/vidar/interpolation.rb
vidar-1.3.0 lib/vidar/interpolation.rb
vidar-1.2.0 lib/vidar/interpolation.rb