Module: JSONAPI::Realizer::Resource
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/jsonapi/realizer/resource.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
- .register(resource_class:, model_class:, adapter:, type:) ⇒ Object
- .resource_mapping ⇒ Object
- .type_mapping ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#model ⇒ Object (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_mapping ⇒ Object
21 22 23 |
# File 'lib/jsonapi/realizer/resource.rb', line 21 def self.resource_mapping @mapping.index_by(&:resource_class) end |
.type_mapping ⇒ Object
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 |