class ActionDispatch::Routing::Mapper

Public Instance Methods

jsonapi_resource(*resources) { || ... } click to toggle source
# File lib/revelry_data/jsonapi_resources_routing_patch.rb, line 9
def jsonapi_resource(*resources, &_block)
  @resource_type = resources.first
  res = JSONAPI::Resource.resource_for(resource_type_with_module_prefix(@resource_type))

  options = resources.extract_options!.dup
  options[:controller] ||= @resource_type
  options.merge!(res.routing_resource_options)
  options[:path] = format_route(@resource_type)

  resource @resource_type, options do
    @scope[:jsonapi_resource] = @resource_type

    if block_given?
      yield
    else
      jsonapi_relationships
    end
  end
end
jsonapi_resources(*resources) { || ... } click to toggle source
# File lib/revelry_data/jsonapi_resources_routing_patch.rb, line 29
def jsonapi_resources(*resources, &_block)
  @resource_type = resources.first
  res = JSONAPI::Resource.resource_for(resource_type_with_module_prefix(@resource_type))

  options = resources.extract_options!.dup
  options[:controller] ||= @resource_type
  options.merge!(res.routing_resource_options)

  options[:param] = :id

  options[:path] = format_route(@resource_type)

  if res.resource_key_type == :uuid
    options[:constraints] = {id: /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(,[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})*/}
  end

  resources @resource_type, options do
    @scope[:jsonapi_resource] = @resource_type

    if block_given?
      yield
    else
      jsonapi_relationships
    end
  end
end