Class: GhDiff::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/gh-diff/option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Option

Returns a new instance of Option.



6
7
8
# File 'lib/gh-diff/option.rb', line 6

def initialize(opts)
  @opts = down_symbolize_key(opts)
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



5
6
7
# File 'lib/gh-diff/option.rb', line 5

def opts
  @opts
end

Instance Method Details

#dotenvObject



14
15
16
# File 'lib/gh-diff/option.rb', line 14

def dotenv
  @dotenv ||= down_symbolize_key(Dotenv.load)
end

#env(prefix = 'GH_') ⇒ Object

returns: ENV variables prefixed with ‘GH_’(default)

and variables defined in dotenv file.


20
21
22
23
24
25
26
27
# 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) ⇒ Object



10
11
12
# File 'lib/gh-diff/option.rb', line 10

def update(opts)
  @opts.update(down_symbolize_key opts)
end

#with_env(prefix = 'GH_') ⇒ Object



29
30
31
# File 'lib/gh-diff/option.rb', line 29

def with_env(prefix='GH_')
  env(prefix).merge(@opts)
end