class Segmentor::Sources::RubySource

RubySource is a source that evaluates ruby code to generate a list of targets DO NOT USE THIS SOURCE IN UNSECURE ENVIRONMENTS

Public Instance Methods

execute() click to toggle source
# 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.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