Class: Ruleby::Core::TypeNode

Inherits:
HashedNode show all
Defined in:
lib/core/nodes.rb

Overview

This node class is used to match the type of a fact. In this case the type is matched exactly (ignoring inheritance).

Direct Known Subclasses

InheritsNode

Instance Attribute Summary

Attributes inherited from AtomNode

#atom

Attributes inherited from ParentNode

#child_nodes

Attributes inherited from Printable

#parent_nodes

Instance Method Summary collapse

Methods inherited from HashedNode

#add_out_node, #initialize

Methods inherited from AtomNode

#==, #initialize, #shareable?, #to_s

Methods inherited from ParentNode

#add_out_node, #initialize, #modify, #propagate_assert, #propagate_modify, #propagate_retract

Methods inherited from Node

#initialize, #resolve

Methods inherited from Printable

#initialize, #print

Constructor Details

This class inherits a constructor from Ruleby::Core::HashedNode

Instance Method Details

#assert(fact) ⇒ Object



430
431
432
433
434
435
436
437
438
439
440
# File 'lib/core/nodes.rb', line 430

def assert(fact)
  k = fact.object.send(@atom.slot)
  # TODO we should create the Assertion object here, not in propogate
  propagate_assert fact, (@values[k] ? @values[k] : {})
rescue NoMethodError => e
  @bucket.add_error Error.new(:no_method, :warn, {
      :object => fact.object.to_s,
      :method => e.name,
      :message => e.message
  })
end

#hash_by(atom) ⇒ Object



422
423
424
# File 'lib/core/nodes.rb', line 422

def hash_by(atom) 
  atom.template.clazz
end

#propagate(propagation_method, fact, out_nodes = @out_nodes) ⇒ Object



442
443
444
445
446
447
448
449
450
# File 'lib/core/nodes.rb', line 442

def propagate(propagation_method, fact, out_nodes=@out_nodes)
  out_nodes.each do |out_node, paths|
    begin
      out_node.send(propagation_method, Assertion.new(fact, paths))
    rescue => e
      @bucket.add_error Error.new(:unknown, :error, {:type => e.class, :message => e.message})
    end
  end
end

#retract(fact) ⇒ Object



426
427
428
# File 'lib/core/nodes.rb', line 426

def retract(fact)
  propagate_retract fact, @values.values.inject({}){|p,c| p.merge(c)} #(@values[k] ? @values[k] : {})
end