<commit_before>Synvert::Rewriter.new 'rails', 'convert_rails_env' do
  description <<-EOF
It converts RAILS_ENV to Rails.env.

  RAILS_ENV
  => Rails.env

  RAILS_ENV == 'development'
  => Rails.env.development?

  'development' == RAILS_ENV
  => Rails.env.development?

  RAILS_ENV != 'development'
  => !Rails.env.development?

  'development' != RAILS_ENV
  => !Rails.env.development?
  EOF

  if_gem 'rails', {gte: '2.3.0'}

  within_files "**/*.{rb,rake}" do
    # RAILS_ENV == 'test'
    # =>
    # Rails.env == 'test'
    with_node type: 'const', to_source: 'RAILS_ENV' do
      replace_with "Rails.env"
    end
    with_node type: 'const', to_source: '::RAILS_ENV' do
      replace_with "Rails.env"
    end
  end

  within_files "**/*.{rb,rake}" do
    # Rails.env == 'test'
    # =>
    # Rails.env.test?
    with_node type: 'send', receiver: 'Rails.env', message: '==' do
      if node.arguments.size == 1
        env = node.arguments.first.to_value
        replace_with "Rails.env.#{env}?"
      end
    end

    # 'development' == Rails.env
    # =>
    # Rails.env.development?
    with_node type: 'send', arguments: {first: 'Rails.env'}, message: '==' do
      env = node.receiver.to_value
      replace_with "Rails.env.#{env}?"
    end

    # Rails.env != 'test'
    # =>
    # !Rails.env.test?
    with_node type: 'send', receiver: 'Rails.env', message: '!=' do
      if node.arguments.size == 1
        env = node.arguments.first.to_value
        replace_with "!Rails.env.#{env}?"
      end
    end

    # 'development' != Rails.env
    # =>
    # !Rails.env.development?
    with_node type: 'send', arguments: {first: 'Rails.env'}, message: '!=' do
      env = node.receiver.to_value
      replace_with "!Rails.env.#{env}?"
    end
  end
end<commit_msg>polish rails/convert_rails_env snippet<commit_after>Synvert::Rewriter.new 'rails', 'convert_rails_env' do
  description <<-EOF
It converts RAILS_ENV to Rails.env.

  RAILS_ENV
  =>
  Rails.env

  \"\#{RAILS_ENV}\"
  =>
  \"\#{Rails.env}\"

  RAILS_ENV == 'development'
  =>
  Rails.env.development?

  'development' == RAILS_ENV
  =>
  Rails.env.development?

  RAILS_ENV != 'development'
  =>
  !Rails.env.development?

  'development' != RAILS_ENV
  =>
  !Rails.env.development?
  EOF

  if_gem 'rails', {gte: '2.3.0'}

  within_files "**/*.{rb,rake}" do
    # RAILS_ENV == 'test'
    # =>
    # Rails.env == 'test'
    with_node type: 'const', to_source: 'RAILS_ENV' do
      replace_with "Rails.env"
    end
    with_node type: 'const', to_source: '::RAILS_ENV' do
      replace_with "Rails.env"
    end
  end

  within_files "**/*.{rb,rake}" do
    # Rails.env == 'test'
    # =>
    # Rails.env.test?
    with_node type: 'send', receiver: 'Rails.env', message: '==', arguments: {size: 1} do
      env = node.arguments.first.to_value
      replace_with "Rails.env.#{env}?"
    end

    # 'development' == Rails.env
    # =>
    # Rails.env.development?
    with_node type: 'send', arguments: {first: 'Rails.env'}, message: '==' do
      env = node.receiver.to_value
      replace_with "Rails.env.#{env}?"
    end

    # Rails.env != 'test'
    # =>
    # !Rails.env.test?
    with_node type: 'send', receiver: 'Rails.env', message: '!=', arguments: {size: 1} do
      env = node.arguments.first.to_value
      replace_with "!Rails.env.#{env}?"
    end

    # 'development' != Rails.env
    # =>
    # !Rails.env.development?
    with_node type: 'send', arguments: {first: 'Rails.env'}, message: '!=' do
      env = node.receiver.to_value
      replace_with "!Rails.env.#{env}?"
    end
  end
end
{'fraction_non_alphanumeric': 0.17138056566788015, 'fraction_numerical': 0.002800336040324839, 'mean_word_length': 2.7560462670872767, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5261742', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1343, 'n_words': 263}