Class: DeadCodeTerminator::Cond::EnvFetch

Inherits:
Base
  • Object
show all
Defined in:
lib/dead_code_terminator/cond/env_fetch.rb

Overview

ENV.fetch(‘PRODUCTION’) s(:send,

s(:const, nil, :ENV), :fetch,
s(:str, "PRODUCTION"))

Constant Summary

Constants inherited from Base

Base::ELSE, Base::THEN

Instance Attribute Summary

Attributes inherited from Base

#ast, #env

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from DeadCodeTerminator::Cond::Base

Instance Method Details

#valueObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/dead_code_terminator/cond/env_fetch.rb', line 10

def value
  return if ast.type != :send

  receiver, method, *args = ast.children
  return unless receiver == s(:const, nil, :ENV) && method == :fetch

  return unless (matched_env_key = given_env_key(args[0]))

  env[matched_env_key] ? THEN : ELSE
end