You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: service_mixin.rb
    path of file: ./repos/manageiq/app/models/mixins
    
    the code of the file until where you have to start completion: module ServiceMixin
  extend ActiveSup
    
  def add_resource(rsc, options = {})
    rsc_type = rsc.class.base_class.name.tableize
    raise _("Cannot connect service with nil ID.") if rsc.id.nil? && rsc_type == "service_templates"

    enforce_single_service_parent(rsc)

    sr = service_resources.detect { |r| r.resource_type == rsc.class.base_class.name && r.resource_id == rsc.id }

    sr || create_service_resource(rsc, options)
  end