class GhDiff::Option
Attributes
opts[R]
Public Class Methods
new(opts)
click to toggle source
# File lib/gh-diff/option.rb, line 6 def initialize(opts) @opts = down_symbolize_key(opts) end
Public Instance Methods
dotenv()
click to toggle source
# File lib/gh-diff/option.rb, line 14 def dotenv @dotenv ||= down_symbolize_key(Dotenv.load) end
env(prefix='GH_')
click to toggle source
returns: ENV variables prefixed with ‘GH_’(default)
and variables defined in dotenv file.
# File lib/gh-diff/option.rb, line 20 def env(prefix='GH_') @envs ||= begin envs = ENV.select { |env| env.start_with? prefix } .map { |k, v| [k.sub(/^#{prefix}/, ''), v] } down_symbolize_key(envs) end @envs.merge(dotenv) end
update(opts)
click to toggle source
# File lib/gh-diff/option.rb, line 10 def update(opts) @opts.update(down_symbolize_key opts) end
with_env(prefix='GH_')
click to toggle source
# File lib/gh-diff/option.rb, line 29 def with_env(prefix='GH_') env(prefix).merge(@opts) end
Private Instance Methods
down_symbolize_key(opts)
click to toggle source
# File lib/gh-diff/option.rb, line 34 def down_symbolize_key(opts) opts.inject({}) do |h, (k, v)| h[k.to_s.downcase.intern] = v; h end end