Module: Acfs::Resource::Persistence::ClassMethods

Defined in:
lib/acfs/resource/persistence.rb

Instance Method Summary collapse

Instance Method Details

#create(data, _opts = {}) ⇒ self

Create a new resource sending given data. If resource cannot be create model will be returned and error hash contains response errors if available.

Saving a resource is a synchronous operation.

Parameters:

  • data (Hash{Symbol, String => Object})

    Data to send in create request.

Returns:

  • (self)

    Newly resource object.

Raises:

See Also:

  • Available options. `:data` will be overridden with provided data hash.
  • #create!


240
241
242
243
244
# File 'lib/acfs/resource/persistence.rb', line 240

def create(data, _opts = {})
  model = new data
  model.save
  model
end

#create!(data, _opts = {}) ⇒ self

Create a new resource sending given data. If resource cannot be created an error will be thrown.

Saving a resource is a synchronous operation.

Parameters:

  • data (Hash{Symbol, String => Object})

    Data to send in create request.

Returns:

  • (self)

    Newly resource object.

Raises:

See Also:

  • Available options. `:data` will be overridden with provided data hash.
  • #create


216
217
218
# File 'lib/acfs/resource/persistence.rb', line 216

def create!(data, _opts = {})
  new(data).tap(&:save!)
end