Class: Fast::Experiment
- Inherits:
-
Object
- Object
- Fast::Experiment
- Defined in:
- lib/fast/experiment.rb
Overview
Fast experiment allow the user to combine single replacements and make multiple changes at the same time. Defining a policy is possible to check if the experiment was successfull and keep changing the file using a specific search.
The experiment have a combination algorithm that recursively check what combinations work with what combinations. It can delay years and because of that it tries a first replacement targeting all the cases in a single file.
You can define experiments and build experimental files to improve some code in
an automated way. Let's create a hook to check if a before or after block
is useless in a specific spec:
Instance Attribute Summary collapse
-
#autoclean ⇒ Object
Returns the value of attribute autoclean.
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#files ⇒ Array<String>
With files from #lookup expression.
-
#files_or_folders ⇒ Object
readonly
Returns the value of attribute files_or_folders.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ok_if ⇒ Object
readonly
Returns the value of attribute ok_if.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
Instance Method Summary collapse
- #autoclean? ⇒ Boolean
-
#edit(&block) ⇒ Object
instance context of a [Fast::Rewriter].
-
#initialize(name, &block) ⇒ Experiment
constructor
A new instance of Experiment.
- #lookup(files_or_folders) ⇒ Object
-
#policy(&block) ⇒ Object
It calls the block after the replacement and use the result to drive the Fast::ExperimentFile#ok_experiments and Fast::ExperimentFile#fail_experiments.
- #run ⇒ void
-
#run_with(file) ⇒ Object
It combines current experiment with Fast::ExperimentFile#run.
- #search(expression) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Experiment
Returns a new instance of Experiment.
96 97 98 99 100 |
# File 'lib/fast/experiment.rb', line 96 def initialize(name, &block) @name = name puts "\nStarting experiment: #{name}" instance_exec(&block) end |
Instance Attribute Details
#autoclean ⇒ Object
Returns the value of attribute autoclean.
94 95 96 |
# File 'lib/fast/experiment.rb', line 94 def autoclean @autoclean end |
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
93 94 95 |
# File 'lib/fast/experiment.rb', line 93 def expression @expression end |
#files ⇒ Array<String>
Returns with files from #lookup expression.
132 133 134 |
# File 'lib/fast/experiment.rb', line 132 def files @files ||= Fast.ruby_files_from(@files_or_folders) end |
#files_or_folders ⇒ Object (readonly)
Returns the value of attribute files_or_folders.
93 94 95 |
# File 'lib/fast/experiment.rb', line 93 def files_or_folders @files_or_folders end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
93 94 95 |
# File 'lib/fast/experiment.rb', line 93 def name @name end |
#ok_if ⇒ Object (readonly)
Returns the value of attribute ok_if.
93 94 95 |
# File 'lib/fast/experiment.rb', line 93 def ok_if @ok_if end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
93 94 95 |
# File 'lib/fast/experiment.rb', line 93 def replacement @replacement end |
Instance Method Details
#autoclean? ⇒ Boolean
142 143 144 |
# File 'lib/fast/experiment.rb', line 142 def autoclean? !!@autoclean end |
#edit(&block) ⇒ Object
instance context of a [Fast::Rewriter]
115 116 117 |
# File 'lib/fast/experiment.rb', line 115 def edit(&block) @replacement = block end |
#lookup(files_or_folders) ⇒ Object
120 121 122 |
# File 'lib/fast/experiment.rb', line 120 def lookup(files_or_folders) @files_or_folders = files_or_folders end |
#policy(&block) ⇒ Object
It calls the block after the replacement and use the result to drive the Fast::ExperimentFile#ok_experiments and Fast::ExperimentFile#fail_experiments.
127 128 129 |
# File 'lib/fast/experiment.rb', line 127 def policy(&block) @ok_if = block end |
#run ⇒ void
138 139 140 |
# File 'lib/fast/experiment.rb', line 138 def run files.map(&method(:run_with)) end |
#run_with(file) ⇒ Object
It combines current experiment with Fast::ExperimentFile#run
104 105 106 |
# File 'lib/fast/experiment.rb', line 104 def run_with(file) ExperimentFile.new(file, self).run end |
#search(expression) ⇒ Object
109 110 111 |
# File 'lib/fast/experiment.rb', line 109 def search(expression) @expression = expression end |