Sha256: 3a2f45d4df2c0db6d170aaefe5f9105e94ccf43bfa7b065cde88405eb23f47fc

Contents?: true

Size: 768 Bytes

Versions: 4

Compression:

Stored size: 768 Bytes

Contents

class ServiceSkeleton
  class ConfigVariable
    attr_reader :name, :key_pattern

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

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

    def sensitive?
      !!@opts[:sensitive]
    end

    def value(env)
      if @opts[:key_pattern]
        matches = env.select { |k, _| @opts[:key_pattern] === k.to_s }
        @blk.call(matches)
      else
        @blk.call(env[@name.to_s])
      end
    end

    def env_keys(env)
      if @opts[:key_pattern]
        env.keys.select { |k| @opts[:key_pattern] === k.to_s }
      else
        env.keys.include?(@name.to_s) ? [@name.to_s] : []
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
service_skeleton-0.0.0.34.g4f6fdb0 lib/service_skeleton/config_variable.rb
service_skeleton-0.0.0.30.g32b8169 lib/service_skeleton/config_variable.rb
service_skeleton-0.0.0.29.g23642ab lib/service_skeleton/config_variable.rb
service_skeleton-0.0.0.28.gae2711b lib/service_skeleton/config_variable.rb