module Segmentor module Sources # RubySource is a source that evaluates ruby code to generate a list of targets # DO NOT USE THIS SOURCE IN UNSECURE ENVIRONMENTS class RubySource < ::Segmentor::Source def execute # evaluate the code # return the result begin targets = eval(code) rescue StandardError => e raise ::Segmentor::Errors::EvaluationError, e.message 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 end end end