app/models/services/reverse_match_service.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Services
  class ReverseMatchService
    include Rails.application.routes.url_helpers

    def initialize(host, protocol)
      raise ArgumentError if host.blank?
      raise ArgumentError if protocol.blank?
      @host = host
      @protocol = protocol
    end

    def build_job(type, concept, subject, match_class)
      raise ArgumentError if type.empty? || concept.nil? || subject.blank? || match_class.blank?
      referer = root_url(host: @host, protocol: @protocol)
      object = rdf_url(concept.origin, host: @host, protocol: @protocol)
      match_classes = Iqvoc::Concept.reverse_match_class_names
      match_class = match_classes[match_class]
      ReverseMatchJob.new(type, concept, match_class, subject, object, referer)
    end

    def add(job)
      Delayed::Job.enqueue(job, queue: 'reverse_matches')
    end
  end
end