Sha256: 920985d38053e139e2067955aba0f4468a1758aa2335b96d98ef1f2f366dcc4d

Contents?: true

Size: 1.24 KB

Versions: 19

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require_relative 'base'
require_relative 'epic'
require_relative 'issue'
require_relative 'linked_issue'
require_relative 'merge_request'
require_relative 'instance_version'
require_relative 'branch'

module Gitlab
  module Triage
    module Resource
      module Context
        EvaluationError = Class.new(RuntimeError)

        def self.build(resource, **options)
          const_name = (resource[:type] || 'Base')
            .to_s.singularize.camelcase

          Resource.const_get(const_name).new(resource, **options).extend(self)
        end

        def eval(ruby)
          instance_eval <<~RUBY, __FILE__, __LINE__ + 1
            begin
              #{ruby}
            rescue StandardError, ScriptError => e
              raise EvaluationError.new(e.message)
            end
          RUBY
        rescue EvaluationError => e
          # This way we could obtain the original backtrace and error
          # If we just let instance_eval raise an error, the backtrace
          # won't contain the actual line where it's giving an error.
          raise e.cause
        end

        private

        def instance_version
          @instance_version ||= InstanceVersion.new(parent: self)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
gitlab-triage-1.44.1 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.44.0 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.43.2 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.43.1 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.43.0 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.42.2 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.42.1 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.42.0 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.41.0 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.40.0 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.30.0 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.29.0 lib/gitlab/triage/resource/context.rb
payping-gitlab-triage-0.1.3 lib/gitlab/triage/resource/context.rb
payping-gitlab-triage-0.1.2 lib/gitlab/triage/resource/context.rb
payping-gitlab-triage-0.1.1 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.28.0 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.27.0 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.26.0 lib/gitlab/triage/resource/context.rb
gitlab-triage-1.25.0 lib/gitlab/triage/resource/context.rb