Class: Eltesla::Experiment
- Inherits:
-
Object
- Object
- Eltesla::Experiment
- Includes:
- Scientist::Experiment
- Defined in:
- lib/eltesla/experiment.rb
Overview
Github scientist experiment implementation for Eltesla
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #clean_trace(backtrace) ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(name) ⇒ Experiment
constructor
A new instance of Experiment.
- #publish(result) ⇒ Object
- #raised(operation, error) ⇒ Object
Constructor Details
#initialize(name) ⇒ Experiment
Returns a new instance of Experiment.
13 14 15 16 17 18 |
# File 'lib/eltesla/experiment.rb', line 13 def initialize(name) location_parts = clean_trace(caller).first.split(/:/) @file = location_parts.first @line = location_parts[1].to_i @name = name || location_parts.last[4..-2] end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
11 12 13 |
# File 'lib/eltesla/experiment.rb', line 11 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
11 12 13 |
# File 'lib/eltesla/experiment.rb', line 11 def line @line end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/eltesla/experiment.rb', line 11 def name @name end |
Class Method Details
.run(name = nil) {|experiment| ... } ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/eltesla/experiment.rb', line 41 def self.run(name = nil) raise 'Missing block' unless block_given? experiment = Eltesla::Experiment.new(name) yield(experiment) experiment.run end |
Instance Method Details
#clean_trace(backtrace) ⇒ Object
35 36 37 38 39 |
# File 'lib/eltesla/experiment.rb', line 35 def clean_trace(backtrace) return backtrace unless defined?(Rails.backtrace_cleaner) Rails.backtrace_cleaner.clean(backtrace) end |
#enabled? ⇒ Boolean
20 21 22 23 |
# File 'lib/eltesla/experiment.rb', line 20 def enabled? # FIXME : Add activation policies true end |
#publish(result) ⇒ Object
31 32 33 |
# File 'lib/eltesla/experiment.rb', line 31 def publish(result) Eltesla::Client.send(result.to_eltesla) end |
#raised(operation, error) ⇒ Object
25 26 27 28 29 |
# File 'lib/eltesla/experiment.rb', line 25 def raised(operation, error) # see "In a Scientist callback" below p "Operation '#{operation}' failed with error '#{error.inspect}'" super # will re-raise end |