Class: DataMapper::Resource::PersistenceState::Immutable

Inherits:
DataMapper::Resource::PersistenceState show all
Defined in:
lib/dm-core/resource/persistence_state/immutable.rb

Overview

a not-persisted/unmodifiable resource

Instance Attribute Summary

Attributes inherited from DataMapper::Resource::PersistenceState

#model, #resource

Instance Method Summary collapse

Methods inherited from DataMapper::Resource::PersistenceState

#initialize

Methods included from Equalizer

#equalize

Constructor Details

This class inherits a constructor from DataMapper::Resource::PersistenceState

Instance Method Details

#commitObject



22
23
24
# File 'lib/dm-core/resource/persistence_state/immutable.rb', line 22

def commit
  self
end

#deleteObject

Raises:



18
19
20
# File 'lib/dm-core/resource/persistence_state/immutable.rb', line 18

def delete
  raise ImmutableError, 'Immutable resource cannot be deleted'
end

#get(subject, *args) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/dm-core/resource/persistence_state/immutable.rb', line 6

def get(subject, *args)
  unless subject.loaded?(resource) || subject.is_a?(Associations::Relationship)
    raise ImmutableError, 'Immutable resource cannot be lazy loaded'
  end

  super
end

#rollbackObject



26
27
28
# File 'lib/dm-core/resource/persistence_state/immutable.rb', line 26

def rollback
  self
end

#set(_subject, _value) ⇒ Object

Raises:



14
15
16
# File 'lib/dm-core/resource/persistence_state/immutable.rb', line 14

def set(_subject, _value)
  raise ImmutableError, 'Immutable resource cannot be modified'
end