<commit_before>require 'set'
require_relative '../../domain/resources/token'
require_relative '../../domain/nodes/node'

class ResourcefulNode < Node

  include Invariant

  def initialize(hsh=nil)
    @resources_added=Hash.new(0)
    @resources_removed=Hash.new(0)
  end

  def initialize_copy(orig)
    super

    #need to clone the resource bag as well...
    @resources = @resources.clone()

    #don't need this. takes too much space
    @diagram = nil

  end

# pools are about resources

  def supports?(klass)
    if klass.eql?(Token)
      untyped?
    else
      #untyped nodes support everything.
      if untyped?
        true
      else
        typed? && types.include?(klass)
      end
    end
  end

  alias_method :support?, :supports?

  def trigger!
    fire!
  end

  def fire!
    stage!
  end

  def stage!
    # this method only 'stages' changes; does not commit them (drawing from git terms)

    if enabled?
      if push?

        edges
        .shuffle
        .select { |e| e.from?(self) }
        .each { |e| e.ping! }

      elsif pull?

        edges
        .shuffle<commit_msg>replace :stage! and other such methods with :trigger. All nodes should have a :trigger! method and it should be the only way to trigger the node.<commit_after>require 'set'
require_relative '../../domain/resources/token'
require_relative '../../domain/nodes/node'

class ResourcefulNode < Node

  include Invariant

  def initialize(hsh=nil)
    @resources_added=Hash.new(0)
    @resources_removed=Hash.new(0)
  end

  def initialize_copy(orig)
    super

    #need to clone the resource bag as well...
    @resources = @resources.clone()

    #don't need this. takes too much space
    @diagram = nil

  end

# pools are about resources

  def supports?(klass)
    if klass.eql?(Token)
      untyped?
    else
      #untyped nodes support everything.
      if untyped?
        true
      else
        typed? && types.include?(klass)
      end
    end
  end

  alias_method :support?, :supports?

  def trigger!

    if enabled?
      if push?

        edges
        .shuffle
        .select { |e| e.from?(self) }
        .each { |e| e.ping! }

      elsif pull?

        edges
        .shuffle
{'fraction_non_alphanumeric': 0.10031774852473899, 'fraction_numerical': 0.0018157058556513845, 'mean_word_length': 2.2222222222222223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3081396', 'n_tokens_mistral': 701, 'n_tokens_neox': 690, 'n_words': 211}