Class: Wongi::Engine::NccPartner
- Defined in:
- lib/wongi-engine/beta/ncc_partner.rb
Instance Attribute Summary collapse
-
#divergent ⇒ Object
Returns the value of attribute divergent.
-
#ncc ⇒ Object
Returns the value of attribute ncc.
Attributes inherited from BetaNode
Instance Method Summary collapse
Methods inherited from BetaNode
#assignment_node, #beta_deactivate_children, #depth, #empty?, #initialize, #overlay, #refresh, #root?, #size, #tokens
Methods included from CoreExt
Constructor Details
This class inherits a constructor from Wongi::Engine::BetaNode
Instance Attribute Details
#divergent ⇒ Object
Returns the value of attribute divergent.
4 5 6 |
# File 'lib/wongi-engine/beta/ncc_partner.rb', line 4 def divergent @divergent end |
#ncc ⇒ Object
Returns the value of attribute ncc.
4 5 6 |
# File 'lib/wongi-engine/beta/ncc_partner.rb', line 4 def ncc @ncc end |
Instance Method Details
#beta_activate(token) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/wongi-engine/beta/ncc_partner.rb', line 6 def beta_activate(token) # p beta_activate: {class: self.class, object_id:, token:} return if tokens.find { |t| t.duplicate? token } .add_token(token) owner = owner_for(token) return unless owner .add_ncc_token(owner, token) owner.node.ncc_deactivate owner end |
#beta_deactivate(token) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wongi-engine/beta/ncc_partner.rb', line 19 def beta_deactivate(token) # p beta_deactivate: {class: self.class, object_id:, token:} # fetch the owner before deleting the token owner = .ncc_owner(token) .remove_token(token) return unless owner ncc.ncc_activate(owner) if .ncc_tokens_for(owner).empty? end |
#owner_for(token) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/wongi-engine/beta/ncc_partner.rb', line 31 def owner_for(token) # find a token in the NCC node that has the same lineage as this token: # - the NCC token will be a direct descendant of the divergent, therefore # - one of this token's ancestors will be a duplicate of that token # TODO: this should be more resilient, but child token creation does not allow for much else at the moment ncc.tokens.find { |t| token.ancestors.any? { |ancestor| ancestor.duplicate?(t) } } end |