Class: DataMapper::Resource::State::Immutable

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

Overview

a not-persisted/unmodifiable resource

Instance Attribute Summary

Attributes inherited from DataMapper::Resource::State

#resource

Instance Method Summary collapse

Methods inherited from DataMapper::Resource::State

#initialize

Methods included from Equalizer

#equalize

Constructor Details

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

Instance Method Details

#commitObject


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

def commit
  self
end

#deleteObject

Raises:


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

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

#get(subject, *args) ⇒ Object


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

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

  super
end

#rollbackObject


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

def rollback
  self
end

#set(subject, value) ⇒ Object

Raises:


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

def set(subject, value)
  raise ImmutableError, 'Immutable resource cannot be modified'
end