Class: Barcoop::Cop::Barcoo::AvoidRailsEnv

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Defined in:
lib/barcoop/cop/barcoo/avoid_rails_env.rb

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/barcoop/cop/barcoo/avoid_rails_env.rb', line 21

def on_send(node)
  receiver, method_name = *node
  if i[production? development? test?].include?(method_name)
    msg = 'Avoid using Rails.env.environment? and prefer adding a feature flag in the configuration file.'
    add_offense(node, :expression, msg) if rails_env?(receiver)
  end
end

#rails_env?(node) ⇒ Boolean

def uncomment_to_test_this_cop()

_foo = Rails.env.production?

end



12
13
14
15
16
17
18
19
# File 'lib/barcoop/cop/barcoo/avoid_rails_env.rb', line 12

def rails_env?(node)
  is_rails_env = false
  if node.send_type?
    receiver, method_name = *node
    is_rails_env = method_name == :env && receiver.const_type? && receiver.const_name == 'Rails'
  end
  return is_rails_env
end