Module: JSONAPI::Realizer::Resource

Extended by:
ActiveSupport::Concern
Defined in:
lib/jsonapi/realizer/resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/jsonapi/realizer/resource.rb', line 6

def model
  @model
end

Class Method Details

.register(resource_class:, model_class:, adapter:, type:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jsonapi/realizer/resource.rb', line 8

def self.register(resource_class:, model_class:, adapter:, type:)
  @mapping ||= Set.new
  raise JSONAPI::Realizer::Error::DuplicateRegistration if @mapping.any? { |realizer| realizer.type == type }
  @mapping << OpenStruct.new({
    resource_class: resource_class,
    model_class: model_class,
    adapter: adapter,
    type: type.dasherize,
    attributes: OpenStruct.new({}),
    relationships: OpenStruct.new({})
   })
end

.resource_mappingObject



21
22
23
# File 'lib/jsonapi/realizer/resource.rb', line 21

def self.resource_mapping
  @mapping.index_by(&:resource_class)
end

.type_mappingObject



25
26
27
# File 'lib/jsonapi/realizer/resource.rb', line 25

def self.type_mapping
  @mapping.index_by(&:type)
end

Instance Method Details

#initialize(model) ⇒ Object



29
30
31
# File 'lib/jsonapi/realizer/resource.rb', line 29

def initialize(model)
  @model = model
end