Class: DataMapper::Resource::VeneerInterface::InstanceWrapper

Inherits:
Veneer::Base::InstanceWrapper show all
Defined in:
lib/veneer/adapters/datamapper/instance_wrapper.rb

Instance Attribute Summary

Attributes inherited from Veneer::Base::InstanceWrapper

#instance, #options

Instance Method Summary collapse

Methods inherited from Veneer::Base::InstanceWrapper

#==, #class, #handle_before_save_error, #initialize, #method_missing, #update

Constructor Details

This class inherits a constructor from Veneer::Base::InstanceWrapper

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Veneer::Base::InstanceWrapper

Instance Method Details

#destroyObject



32
33
34
35
# File 'lib/veneer/adapters/datamapper/instance_wrapper.rb', line 32

def destroy
  instance.destroy
  self
end

#new_record?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/veneer/adapters/datamapper/instance_wrapper.rb', line 28

def new_record?
  instance.respond_to?(:new?) ? instance.new? : instance.new_record?
end

#saveObject



6
7
8
9
10
11
12
13
14
# File 'lib/veneer/adapters/datamapper/instance_wrapper.rb', line 6

def save
  result = false
  instance.class.transaction do
    result = instance.save
  end
  result
rescue ::Veneer::Errors::BeforeSaveError => e
  handle_before_save_error(e)
end

#save!Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/veneer/adapters/datamapper/instance_wrapper.rb', line 16

def save!
  result = false
  instance.class.transaction do
    result = instance.save
    raise ::Veneer::Errors::NotSaved unless result
    result
  end
  result
rescue ::Veneer::Errors::BeforeSaveError => e
  raise ::Veneer::Errors::NotSaved, e.message
end