Sha256: 872a60f62ef76b65399716424e060114c5ea319573088c430968b7e3e8c8c901

Contents?: true

Size: 621 Bytes

Versions: 4

Compression:

Stored size: 621 Bytes

Contents

module Ellen
  class Env
    attr_reader :key, :description, :options

    def initialize(key, description, options = {})
      @key = key.to_s
      @description = description
      @options = options
    end

    def validate
      error if required? && missing?
    end

    def to_usage
      "    %-30s - %s" % [key, description]
    end

    private

    def required?
      !options[:optional]
    end

    def missing?
      !ENV[key]
    end

    def error
      raise MissingRequiredKeyError, %<ENV["#{key}"] is required but missing>
    end

    class MissingRequiredKeyError < StandardError
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ellen-0.1.0 lib/ellen/env.rb
ellen-0.0.9 lib/ellen/env.rb
ellen-0.0.8 lib/ellen/env.rb
ellen-0.0.7 lib/ellen/env.rb