<commit_before>
module Oboe
  class InstallGenerator < ::Rails::Generators::Base
    source_root File.join(File.dirname(__FILE__), 'templates')
    desc "Copies an oboe initializer files to your application."

    def copy_initializer
      # Set defaults
      @tracing_mode = 'through'
      @sampling_rate = '300000'
      @verbose = 'false'

      say ""
      say set_color "Welcome to the TraceView Ruby instrumentation setup.", :green, :bold
      say ""
      say "To instrument your Rails application, you have the option to setup sampling strategies here."
      say ""
      say set_color "Documentation Links", :magenta
      say "-------------------"
      say ""
      say "Details on configuring your sampling rate:"
      say "http://support.tv.appneta.com/support/solutions/articles/86336-configuring-sampling"
      say ""
      say "More information on instrumenting Ruby applications can be found here:"
      say "http://support.tv.appneta.com/support/solutions/articles/86393-instrumenting-ruby-apps"
      while true do
        say ""
        say set_color "Tracing Mode", :magenta
        say "------------"
        say "Tracing Mode determines when traces should be initiated for incoming requests.  Valid"
        say "options are #{set_color "always", :yellow}, #{set_color "through", :yellow} (when using an instrumented Apache or Nginx) and #{set_color "never", :yellow}."
        say ""
        say "If you're not using an instrumented Apache or Nginx, set this directive to #{set_color "always", :yellow} in"
        say "order to initiate tracing from Ruby."
        say ""
        user_tracing_mode = ask set_color "* Tracing Mode? [through]:", :yellow
        user_tracing_mode.downcase!

        break if user_tracing_mode.blank?
        valid = ['always', 'through', 'never'].include?(user_tracing_mode)
        say set_color "Valid values are 'always', 'through' or 'never'", :red, :bold unless valid
        if valid
          @tracing_mode = user_tracing_mode
          break
        end
      end

      if @tracing_mode == "always"
        while true do
          say ""
          say set_color "Sampling Rate", :green
          say "-------------"
          say "This value reflects the number of requests out of every million that will be traced, and must be an integer between 0 and 1000000. Default is 300000 (30%)."
          say ""
          user_sampling_rate = ask set_color "* Sampling Rate? [300000]:", :yellow
          break if user_sampling_rate.blank?

          valid = user_sampling_rate.to_i.between?(1, 1000000)
          say set_color "Sampling Rate must be a number between 1 and 1000000", :red, :bold unless valid
          if valid
            @sampling_rate = user_sampling_rate.to_i
            break
          end
        end
      end

      say ""
      say "You can change these values in the future by modifying config/initializers/oboe.rb"
      say ""
      say "Thanks! Creating the TraceView initializer..."
      say ""

      template "oboe_initializer.rb", "config/initializers/oboe.rb"
    end
  end
end
<commit_msg>Use Thor::Shell basic instance var for set_color<commit_after>
module Oboe
  class InstallGenerator < ::Rails::Generators::Base
    source_root File.join(File.dirname(__FILE__), 'templates')
    desc "Copies an oboe initializer files to your application."

    def copy_initializer
      # Set defaults
      @tracing_mode = 'through'
      @sampling_rate = '300000'
      @verbose = 'false'

      say ""
      say shell.set_color "Welcome to the TraceView Ruby instrumentation setup.", :green, :bold
      say ""
      say "To instrument your Rails application, you have the option to setup sampling strategies here."
      say ""
      say shell.set_color "Documentation Links", :magenta
      say "-------------------"
      say ""
      say "Details on configuring your sampling rate:"
      say "http://support.tv.appneta.com/support/solutions/articles/86336-configuring-sampling"
      say ""
      say "More information on instrumenting Ruby applications can be found here:"
      say "http://support.tv.appneta.com/support/solutions/articles/86393-instrumenting-ruby-apps"
      while true do
        say ""
        say shell.set_color "Tracing Mode", :magenta
        say "------------"
        say "Tracing Mode determines when traces should be initiated for incoming requests.  Valid"
        say "options are #{shell.set_color "always", :yellow}, #{shell.set_color "through", :yellow} (when using an instrumented Apache or Nginx) and #{shell.set_color "never", :yellow}."
        say ""
        say "If you're not using an instrumented Apache or Nginx, set this directive to #{shell.set_color "always", :yellow} in"
        say "order to initiate tracing from Ruby."
        say ""
        user_tracing_mode = ask shell.set_color "* Tracing Mode? [through]:", :yellow
        user_tracing_mode.downcase!

        break if user_tracing_mode.blank?
        valid = ['always', 'through', 'never'].include?(user_tracing_mode)
        say shell.set_color "Valid values are 'always', 'through' or 'never'", :red, :bold unless valid
        if valid
          @tracing_mode = user_tracing_mode
          break
        end
      end

      if @tracing_mode == "always"
        while true do
          say ""
          say shell.set_color "Sampling Rate", :green
          say "-------------"
          say "This value reflects the number of requests out of every million that will be traced, and must be an integer between 0 and 1000000. Default is 300000 (30%)."
          say ""
          user_sampling_rate = ask shell.set_color "* Sampling Rate? [300000]:", :yellow
          break if user_sampling_rate.blank?

          valid = user_sampling_rate.to_i.between?(1, 1000000)
          say shell.set_color "Sampling Rate must be a number between 1 and 1000000", :red, :bold unless valid
          if valid
            @sampling_rate = user_sampling_rate.to_i
            break
          end
        end
      end

      say ""
      say "You can change these values in the future by modifying config/initializers/oboe.rb"
      say ""
      say "Thanks! Creating the TraceView initializer..."
      say ""

      template "oboe_initializer.rb", "config/initializers/oboe.rb"
    end
  end
end

{'fraction_non_alphanumeric': 0.10325655281969817, 'fraction_numerical': 0.01715647339158062, 'mean_word_length': 2.4198804997284085, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6711412', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1698, 'n_words': 604}