Class: Hold::InMemory::IdentitySetRepository
Instance Method Summary
collapse
#cell, #get_many_by_ids, #id_cell, #load, #reload, #update, #update_by_id
#can_get_class?, #can_set_class?, #store_new
Constructor Details
6
7
8
9
|
# File 'lib/hold/in_memory/identity_set_repository.rb', line 6
def initialize(allocates_ids=false)
@by_id = {}
@id_seq = 0 if allocates_ids
end
|
Instance Method Details
#allocates_ids? ⇒ Boolean
11
12
13
|
# File 'lib/hold/in_memory/identity_set_repository.rb', line 11
def allocates_ids?
!!@id_seq
end
|
#contains?(object) ⇒ Boolean
27
28
29
30
|
# File 'lib/hold/in_memory/identity_set_repository.rb', line 27
def contains?(object)
id = object.id or raise MissingIdentity
@by_id.include?(id)
end
|
#contains_id?(id) ⇒ Boolean
44
45
46
|
# File 'lib/hold/in_memory/identity_set_repository.rb', line 44
def contains_id?(id)
@by_id.include?(id)
end
|
#delete(object) ⇒ Object
22
23
24
25
|
# File 'lib/hold/in_memory/identity_set_repository.rb', line 22
def delete(object)
id = object.id or raise MissingIdentity
delete_id(id)
end
|
#delete_id(id) ⇒ Object
40
41
42
|
# File 'lib/hold/in_memory/identity_set_repository.rb', line 40
def delete_id(id)
@by_id.delete(id)
end
|
#get_all ⇒ Object
32
33
34
|
# File 'lib/hold/in_memory/identity_set_repository.rb', line 32
def get_all
@by_id.values
end
|
#get_by_id(id) ⇒ Object
36
37
38
|
# File 'lib/hold/in_memory/identity_set_repository.rb', line 36
def get_by_id(id)
value = @by_id[id] and value.dup
end
|
#store(object) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/hold/in_memory/identity_set_repository.rb', line 15
def store(object)
id = object.id
object.send(:id=, id = @id_seq += 1) if @id_seq && !id
raise MissingIdentity unless id
@by_id[id] = object
end
|