Class: Segmentor::Sources::RubySource
- Inherits:
-
Segmentor::Source
- Object
- ActiveRecord::Base
- Segmentor::Source
- Segmentor::Sources::RubySource
- Defined in:
- lib/segmentor/sources/ruby_source.rb
Overview
RubySource is a source that evaluates ruby code to generate a list of targets DO NOT USE THIS SOURCE IN UNSECURE ENVIRONMENTS
Instance Method Summary collapse
Instance Method Details
#execute ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/segmentor/sources/ruby_source.rb', line 6 def execute # evaluate the code # return the result begin targets = eval(code) rescue StandardError => e raise ::Segmentor::Errors::EvaluationError, e. end targets = targets.is_a?(Array) ? targets : [targets] # all targets should be a ::Segment::Target if targets.any? { |target| !target.is_a?(::Segmentor::Target) } raise ::Segmentor::Errors::EvaluationError, 'all returned items should be ::Segment::Target' end targets end |