Sha256: b21bb1ee35d7a590655f016b39d21ddb18589e2522d903e852ccb00d3ae8d156

Contents?: true

Size: 906 Bytes

Versions: 13

Compression:

Stored size: 906 Bytes

Contents

# frozen_string_literal: true

module 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)
      @opts[:sensitive]
    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

13 entries across 13 versions & 1 rubygems

Version Path
service_skeleton-2.2.0 lib/service_skeleton/config_variable.rb
service_skeleton-2.1.0 lib/service_skeleton/config_variable.rb
service_skeleton-1.0.5 lib/service_skeleton/config_variable.rb
service_skeleton-2.0.2 lib/service_skeleton/config_variable.rb
service_skeleton-2.0.1 lib/service_skeleton/config_variable.rb
service_skeleton-2.0.0 lib/service_skeleton/config_variable.rb
service_skeleton-1.0.4 lib/service_skeleton/config_variable.rb
service_skeleton-0.0.0.1.ENOTAG lib/service_skeleton/config_variable.rb
service_skeleton-1.0.3 lib/service_skeleton/config_variable.rb
service_skeleton-1.0.2 lib/service_skeleton/config_variable.rb
service_skeleton-1.0.1 lib/service_skeleton/config_variable.rb
service_skeleton-0.0.0.49.g47046b9 lib/service_skeleton/config_variable.rb
service_skeleton-0.0.0.48.g4a40599 lib/service_skeleton/config_variable.rb