class Dpl::Env::Env
Attributes
Public Class Methods
Source
# File lib/dpl/helper/env.rb, line 17 def initialize(env, args) @env = env @opts = args.last.is_a?(Hash) ? args.pop : {} @strs = args.map(&:to_s).map(&:upcase) end
Public Instance Methods
Source
# File lib/dpl/helper/env.rb, line 30 def description(cmd) strs = self.strs.map { |str| "#{str}_" } strs += self.strs if opts[:allow_skip_underscore] strs = strs.size > 1 ? "[#{strs.sort.join('|')}]" : strs.join "Options can be given via env vars if prefixed with `#{strs}`. #{example(cmd)}" end
Source
# File lib/dpl/helper/env.rb, line 37 def example(cmd) return unless opt = cmd.opts.detect { |option| option.secret? } env = strs.map { |str| "`#{str}_#{opt.name.upcase}=<#{opt.name}>`" } env += strs.map { |str| "`#{str}#{opt.name.upcase}=<#{opt.name}>`" } if opts[:allow_skip_underscore] "E.g. the option `--#{opt.name}` can be given as #{sentence(env)}." end
Source
# File lib/dpl/helper/env.rb, line 45 def sentence(strs) return strs.join if strs.size == 1 [strs[0..-2].join(', '), strs[-1]].join(' or ') end
Private Instance Methods
Source
# File lib/dpl/helper/env.rb, line 53 def dealias(key) opt = cmd.opts.detect { |option| option.aliases.include?(key) } opt ? opt.name : key end
Source
# File lib/dpl/helper/env.rb, line 68 def keys_for(str, key) keys = [["#{str}_", key.upcase].join] keys << [str, key.upcase].join if opts[:allow_skip_underscore] keys end
Source
# File lib/dpl/helper/env.rb, line 58 def unprefix(key) strs.inject(key) { |key, str| key.sub(/^#{str}_?/, '') } end