Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a vessel's children spill into its parent when it is deleted #3

Open
microlith57 opened this issue Apr 29, 2019 · 1 comment
Open

Comments

@microlith57
Copy link
Contributor

Current behaviour

A
- B
  - CD

delete B

A
C
D

(All paradoxes)

Proposed behaviour

A
- B
  - CD

delete B

A
- CD

(C and D children of A)

@microlith57
Copy link
Contributor Author

def delete(id)
  @vessels.delete self[id]
  (0...@vessels.size).each do |v_id|
    v = self[v_id]
    # Decrement parents / orphan vessels as needed
    v.parent -= 1 if v.parent > id
    v.parent = v_id if v.parent == id
    # Decrement owners / disown vessels as needed
    v.owner -= 1 if v.owner > id
    v.owner = v_id if v.owner == id
  end
end

-->

def delete(id)
 to_delete = self[id]
  @vessels.delete to_delete
  (0...@vessels.size).each do |v_id|
    v = self[v_id]
    # Decrement parents / orphan vessels as needed
    v.parent -= 1 if v.parent > id
    if v.parent == id
      if to_delete.parent == id
        # Deleted vessel is a paradox
        v.parent = v_id
      else
        v.parent = to_delete.parent
      end
    end
    # Decrement owners / disown vessels as needed
    v.owner -= 1 if v.owner > id
    v.owner = v_id if v.owner == id
  end
end
  • Review
  • Convert to PR / commit / whatever

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant