Sha256: 71d69272272b8faafa0d3fc21ebc79a458e4e7fc0c35ab50b89e2c147a9b21e9

Contents?: true

Size: 851 Bytes

Versions: 1

Compression:

Stored size: 851 Bytes

Contents

# frozen_string_literal: true

class ServiceSkeleton
  class ConfigVariable
    attr_reader :name, :value

    def initialize(name, env, **opts, &blk)
      @name = name
      @opts = opts
      @blk  = blk

      @value = pluck_value(env)
    end

    def method_name(svc_name)
      @name.to_s.gsub(/\A#{Regexp.quote(svc_name)}_/i, '').downcase
    end

    def redact!(env)
      if @opts[:sensitive]
        env[@name.to_s] = "*SENSITIVE*" if env.has_key?(@name.to_s)
      end
    end

    private

    def maybe_default(env)
      if env.has_key?(@name.to_s)
        yield
      else
        if @opts.has_key?(:default)
          @opts[:default]
        else
          raise ServiceSkeleton::Error::InvalidEnvironmentError,
                "Value for required environment variable #{@name} not specified"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
service_skeleton-0.0.0.41.g9507cda lib/service_skeleton/config_variable.rb