Class: ODDB::AcceptOrphan

Inherits:
Object show all
Defined in:
src/command/accept_orphan.rb

Instance Method Summary (collapse)

Constructor Details

- (AcceptOrphan) initialize(orphan, pointers, otype, origin = nil)

A new instance of AcceptOrphan



9
10
11
12
13
14
# File 'src/command/accept_orphan.rb', line 9

def initialize(orphan, pointers, otype, origin=nil)
  @orphan = orphan
  @pointers = pointers
  @orphantype = otype
  @origin = origin
end

Instance Method Details

- (Object) execute(app)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'src/command/accept_orphan.rb', line 15

def execute(app)
  pointer = ODDB::Persistence::Pointer.new(@orphantype)
  digest = Digest::MD5.hexdigest(@orphan.sort.to_s)
  info = app.accepted_orphans.fetch(digest) {
    inf = app.update(pointer.creator, @orphan, @origin)
    app.accepted_orphans.store(digest, inf)
    app.accepted_orphans.odba_store
    inf
  }
  @pointers.each { |ptr|
    parent = ptr.resolve(app)
    old_info = parent.send(@orphantype)
    writer = @orphantype.to_s << "="
    parent.send(writer, info)
    parent.odba_store
    if(old_info && old_info.empty?)
      app.delete(old_info.pointer)
    end
  }
end