Class: JSONAPI::Realizer::Action::Create
- Inherits:
-
JSONAPI::Realizer::Action
- Object
- JSONAPI::Realizer::Action
- JSONAPI::Realizer::Action::Create
- Defined in:
- lib/jsonapi/realizer/action/create.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
Returns the value of attribute resource.
Attributes inherited from JSONAPI::Realizer::Action
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(payload:, headers:, scope: nil) ⇒ Create
constructor
A new instance of Create.
- #model ⇒ Object
Methods inherited from JSONAPI::Realizer::Action
Constructor Details
#initialize(payload:, headers:, scope: nil) ⇒ Create
Returns a new instance of Create.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/jsonapi/realizer/action/create.rb', line 7 def initialize(payload:, headers:, scope: nil) raise Error::MissingContentTypeHeader unless headers.key?("Content-Type") raise Error::InvalidContentTypeHeader unless headers.fetch("Content-Type") == JSONAPI::MEDIA_TYPE super(payload: payload, headers: headers, scope: scope) @resource = resource_class.new(relation.new) raise Error::MissingRootProperty unless payload.key?("data") || payload.key?("errors") || payload.key?("meta") raise Error::MissingTypeResourceProperty if payload.key?("data") && data.kind_of?(Hash) && !data.key?("type") raise Error::MissingTypeResourceProperty if payload.key?("data") && data.kind_of?(Array) && !data.all? {|resource| resource.key?("type")} end |
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
5 6 7 |
# File 'lib/jsonapi/realizer/action/create.rb', line 5 def resource @resource end |
Instance Method Details
#call ⇒ Object
20 21 22 23 24 |
# File 'lib/jsonapi/realizer/action/create.rb', line 20 def call adapter.assign_attributes_via_call(resource.model, {id: id}) if id adapter.assign_attributes_via_call(resource.model, attributes) adapter.assign_relationships_via_call(resource.model, relationships) end |
#model ⇒ Object
26 27 28 |
# File 'lib/jsonapi/realizer/action/create.rb', line 26 def model resource.model end |