<commit_before>
= RubyTerminal -- A ruby environment terminal for program

RubyTerminal prepares a ruby runtime environment for launching new ruby process instantly.
For example, a big Rails project may need 5 seconds to launch a test process even you just
run simple method test which just cost 0.1 second when you are doing TDD. RubyTerminal can
help you get rid of this kind waiting.

== How it works

Start RubyTerminal by the following command after installed rubyterminal gem:

  rt <ruby_environment_script_file_path>

After RubyTerminal started, it will create a '.terminal.running' file to mark it's launching
directory, the file would be deleted after RubyTerminal shutdown. 
Then RubyTerminal starts look for a file named '.terminal.input' in it's launching directory
and read it's content as command to execute in a forked process. The output of command
execution would be put into another file named '.terminal.output' in the same directory.

There are two model to create a '.terminal.input' by RubyTerminal, one is a command could be
used in a terminal called 'ert', another one is a ruby file could be loaded in a ruby script.

=== Execute ruby script in RubyTerminal by injecting 'ert' inside the script

Put the following code in first line code would be run before your ruby code, e.g. first
line in test_helper.rb:

  require 'ert'

When RubyTerminal is detected by the script, it will create a '.terminal.input' file with
current script execution command and arguments, then wait for execution output and exit
when the '.terminal.input' file gone, which is deleted by the RubyTerminal usually after
the execution finished.

If it does not find RubyTerminal, nothing happens and your ruby script would be run as
normal.

=== Execute ruby script in RubyTerminal by a terminal ert command

ert has same usage with ruby expect you should not type in 'ruby', for example:

  ert test/unit/blabla_test.rb -n test_method_blabla

And you also could run this command inside sub-directory of the RubyTerminal launching
directory:

  You RubyTerminal may launch at /User/xx/project
  You could run ert at /User/xx/project/test/unit

When you use 'ert' in terminal, there is no need to add code:

  require 'ert'

inside your project, otherwise you just use 'ruby' in terminal is OK.

== Working Example:

My project got problem with spending too much time to wait for rails test process starts.
My test just need 1 sec to run, but the process need 5 sec to launch. As many time as I
run my test, as much time as I waste on waiting on launching the process.

To setup using RubyTerminal cleanly, I created a new ruby script called 'test_environment.rb'
as my project's RubyTerminal environment initializer inside the 'test' directory with
the following code:

  ENV["RAILS_ENV"] = "test"
  require File.expand_path(File.dirname(__FILE__) + "/../config/environment")

Then add the following code at the very top of 'test/test_helper.rb':

  require 'rubygems' # unless you didn't install ruby_terminal from gem
  # Define reload paths as you need here, default value is ['app', 'lib'], usually you don't
  # need change the default value. We'll talk more about it at Limitation paragraph below.
  # RELOAD_PATHS = ['app', 'lib']
  require 'ert'

Then, start RubyTerminal in my project root directory with test/test_environment.rb while
developing.

  rt test/test_environment.rb

Done. Develop as usual.

== Limitation

=== Initialization of environment

As RubyTerminal loads your ruby environment script as cache, and forks a new process to execute
you ruby script, anything loaded by your ruby environment script would not be reloaded unless you
do it in your ruby execution script. For example, if you load your 'test/test_helper.rb' in
RubyTerminal 'rt test/test_helper.rb', and your test_helper.rb loads some ruby files, for
example:

  require 'messaging'

Then any change inside 'messaging' would not be reloaded in RubyTerminal. You'll need to restart
RubyTerminal or write some script in your test_helper.rb to reload 'messaging'.

As Rails project would load all your models, controllers, helpers and libs as cache in test model,
RubyTerminal will reload all files inside 'RAILS_ROOT/app' and 'RAILS_ROOT/lib' as default after
you required 'ert' (Do same thing when you use 'ert' in terminal). You could define a const
RELOAD_PATHS to replace the default reload paths.

If you want to take care of reloading some source files by yourself, you could take a look at
'ruby_terminal/reloader', which could help your reload source files easier.

Make sure you do reload source work or define RELOAD_PATHS for you rails project before code:

  require 'ert'

== Credits

[<b>rails-test-serving</b>] For showing me how to clean up rails project environment.

= Other stuff<commit_msg>added --rails_test option doc<commit_after>
= RubyTerminal -- A ruby environment terminal for program

RubyTerminal prepares a ruby runtime environment for launching new ruby process instantly.
For example, a big Rails project may need 5 seconds to launch a test process even you just
run simple method test which just cost 0.1 second when you are doing TDD. RubyTerminal can
help you get rid of this kind waiting.

== How it works

Start RubyTerminal by the following command after installed rubyterminal gem:

  rt <ruby_environment_script_file_path>

After RubyTerminal started, it will create a '.terminal.running' file to mark it's launching
directory, the file would be deleted after RubyTerminal shutdown. 
Then RubyTerminal starts look for a file named '.terminal.input' in it's launching directory
and read it's content as command to execute in a forked process. The output of command
execution would be put into another file named '.terminal.output' in the same directory.

There are two model to create a '.terminal.input' by RubyTerminal, one is a command could be
used in a terminal called 'ert', another one is a ruby file could be loaded in a ruby script.

=== Execute ruby script in RubyTerminal by injecting 'ert' inside the script

Put the following code in first line code would be run before your ruby code, e.g. first
line in test_helper.rb:

  require 'ert'

When RubyTerminal is detected by the script, it will create a '.terminal.input' file with
current script execution command and arguments, then wait for execution output and exit
when the '.terminal.input' file gone, which is deleted by the RubyTerminal usually after
the execution finished.

If it does not find RubyTerminal, nothing happens and your ruby script would be run as
normal.

=== Execute ruby script in RubyTerminal by a terminal ert command

ert has same usage with ruby expect you should not type in 'ruby', for example:

  ert test/unit/blabla_test.rb -n test_method_blabla

And you also could run this command inside sub-directory of the RubyTerminal launching
directory:

  You RubyTerminal may launch at /User/xx/project
  You could run ert at /User/xx/project/test/unit

When you use 'ert' in terminal, there is no need to add code:

  require 'ert'

inside your project, otherwise you just use 'ruby' in terminal is OK.

== Working Example:

My project got problem with spending too much time to wait for rails test process starts.
My test just need 1 sec to run, but the process need 5 sec to launch. As many time as I
run my test, as much time as I waste on waiting on launching the process.

To setup using RubyTerminal cleanly, I created a new ruby script called 'test_environment.rb'
as my project's RubyTerminal environment initializer inside the 'test' directory with
the following code:

  ENV["RAILS_ENV"] = "test"
  require File.expand_path(File.dirname(__FILE__) + "/../config/environment")

Then add the following code at the very top of 'test/test_helper.rb':

  require 'rubygems' # unless you didn't install ruby_terminal from gem
  # Define reload paths as you need here, default value is ['app', 'lib'], usually you don't
  # need change the default value, and you must launch RubyTerminal in the root directory of
  # your Rails project. We'll talk more about it at Limitation paragraph below.
  # RELOAD_PATHS = ['app', 'lib']
  require 'ert'

Then, start RubyTerminal in my project root directory with test/test_environment.rb while
developing.

  rt test/test_environment.rb

Done. Develop as usual.

For the test/test_environment.rb, RubyTerminal provides an option --rails_test to let you
just do it with RubyTerminal without creating new file:

  rt --rails_test

Code above will do exactly same with test_environment.rb above.

== Limitation

=== Initialization of environment

As RubyTerminal loads your ruby environment script as cache, and forks a new process to execute
you ruby script, anything loaded by your ruby environment script would not be reloaded unless you
do it in your ruby execution script. For example, if you load your 'test/test_helper.rb' in
RubyTerminal 'rt test/test_helper.rb', and your test_helper.rb loads some ruby files, for
example:

  require 'messaging'

Then any change inside 'messaging' would not be reloaded in RubyTerminal. You'll need to restart
RubyTerminal or write some script in your test_helper.rb to reload 'messaging'.

As Rails project would load all your models, controllers, helpers and libs as cache in test model,
RubyTerminal will reload all files inside 'RAILS_ROOT/app' and 'RAILS_ROOT/lib' as default after
you required 'ert' (Do same thing when you use 'ert' in terminal). You could define a const
RELOAD_PATHS to replace the default reload paths.

If you want to take care of reloading some source files by yourself, you could take a look at
'ruby_terminal/reloader', which could help your reload source files easier.

Make sure you do reload source work or define RELOAD_PATHS for your Rails project before code:

  require 'ert'

== Credits

[<b>rails-test-serving</b>] For showing me how to clean up rails project environment.

= Other stuff
{'fraction_non_alphanumeric': 0.0522072162870389, 'fraction_numerical': 0.0010078613182826044, 'mean_word_length': 4.410577971646674, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3128191', 'n_tokens_mistral': 2744, 'n_tokens_neox': 2556, 'n_words': 1472}