Class: V1::MultiPoolPositionResource

Inherits:
JSONAPI::Resource
  • Object
show all
Defined in:
app/resources/v1/multi_pool_position_resource.rb

Overview

Note:

This resource cannot be directly accessed. Reference via MultiPoolResource includes

MultiPoolPositionResource provides a JSON:API representation of the MultiPoolPosition model. It allows API clients to query, filter, and retrieve multi-pool-position-related information.

if required

Relationships: * multi_pool MultiPoolResource * pacbio_pool Pacbio::PoolResource

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#created_atObject

TODO: Add ONT support has_one :ont_pool, class_name: ‘Ont::Pool’, relation_name: :ont_pool



26
# File 'app/resources/v1/multi_pool_position_resource.rb', line 26

attributes :position, :pool_id, :pool_type, :created_at

#pacbio_pool_attributes=(value) ⇒ Hash (writeonly)

Returns attributes for creating/updating nested pacbio_pool.

Returns:

  • (Hash)

    attributes for creating/updating nested pacbio_pool



30
# File 'app/resources/v1/multi_pool_position_resource.rb', line 30

attribute :pacbio_pool_attributes

#pool_idInteger

Returns the id of the pool associated with this position.

Returns:

  • (Integer)

    the id of the pool associated with this position



26
# File 'app/resources/v1/multi_pool_position_resource.rb', line 26

attributes :position, :pool_id, :pool_type, :created_at

#pool_typeString

Returns the type of the pool associated with this position.

Returns:

  • (String)

    the type of the pool associated with this position



26
# File 'app/resources/v1/multi_pool_position_resource.rb', line 26

attributes :position, :pool_id, :pool_type, :created_at

#positionString

Returns the position within the multi_pool .e.g. “A1”.

Returns:

  • (String)

    the position within the multi_pool .e.g. “A1”



26
# File 'app/resources/v1/multi_pool_position_resource.rb', line 26

attributes :position, :pool_id, :pool_type, :created_at

Class Method Details

.resource_klass_for(type) ⇒ Object

JSONAPI::Resources polymorphic support. This gets around issues with namespaced lookups



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/resources/v1/multi_pool_position_resource.rb', line 52

def self.resource_klass_for(type)
  # We need to distinguish between Pacbio::Pool and Ont::Pool types here.
  # We can either update json_api_resources to use different type names internally, add
  # more context to this override to identify both cases or retrieve ONT pools differently.
  #
  # This is a bug in JSONAPI::Resources when using namespaced polymorphic relationships
  # as both Ont::Pool and Pacbio::Pool have type 'pools'. This is due to the demodulization
  # of type and pluralization that happens internally See https://github.com/sanger/jsonapi-resources/blob/master/lib/jsonapi/basic_resource.rb#L454
  # We can work around it by explicitly checking for 'pools' and mapping it to Pacbio::Pool
  # for mvp but when we come to add ONT support we will need a better solution.
  #
  # If we don't map 'pools' here it will attempt to use V1::PoolResource which isn't backed
  # by a model and it will fail the join lookup here https://github.com/sanger/jsonapi-resources/blob/master/lib/jsonapi/active_relation/join_manager.rb#L70
  case type
  when 'pools'
    type = 'Pacbio::Pool'
  end
  super
end

Instance Method Details

#fetchable_fieldsObject



46
47
48
# File 'app/resources/v1/multi_pool_position_resource.rb', line 46

def fetchable_fields
  super - %i[pacbio_pool_attributes]
end