Sha256: 130da36bd090e12cb9b95035b6942ec347b81291668e6834d3dfe67ee61f7941

Contents?: true

Size: 791 Bytes

Versions: 4

Compression:

Stored size: 791 Bytes

Contents

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
segmentor-0.0.2.3 lib/segmentor/sources/ruby_source.rb
segmentor-0.0.2.2 lib/segmentor/sources/ruby_source.rb
segmentor-0.0.2.1 lib/segmentor/sources/ruby_source.rb
segmentor-0.0.1 lib/segmentor/sources/ruby_source.rb