module JSONAPI::Record::Creatable::ClassMethods
Public Instance Methods
creatable_attribute_names()
click to toggle source
Allows to override the attributes for creating a resource. @return [Array<Symbol>]
# File lib/jsonapi/record/creatable.rb, line 49 def creatable_attribute_names resource_attribute_names end
create(record)
click to toggle source
@param record [JSONAPI::Record::Base] @return [JSONAPI::Record::Base]
# File lib/jsonapi/record/creatable.rb, line 13 def create(record) response_document = JSONAPI::SimpleClient.create( collection_uri, default_headers, record.to_payload ) case response_document when Types::Success, Types::Failure record.new(parse(response_document)) when Types::Document record.new(persisted: true) end end
create!(record)
click to toggle source
@param record [JSONAPI::Record::Base] @raise [JSONAPI::SimpleClient::UnprocessableEntity] if create fails. @return [JSONAPI::Record::Base]
# File lib/jsonapi/record/creatable.rb, line 30 def create!(record) raise_exception_when_errors { create(record) } end
create_with(attributes)
click to toggle source
@param attributes [Hash] @return [JSONAPI::Record::Base]
# File lib/jsonapi/record/creatable.rb, line 36 def create_with(attributes) create(new(attributes)) end
create_with!(attributes)
click to toggle source
@param attributes [Hash] @raise [JSONAPI::SimpleClient::UnprocessableEntity] if create fails. @return [JSONAPI::Record::Base]
# File lib/jsonapi/record/creatable.rb, line 43 def create_with!(attributes) create!(new(attributes)) end