Class: Cheri::Builder::Context::ConnectionMinder

Inherits:
Object
  • Object
show all
Defined in:
lib/cheri/builder/context.rb

Overview

We want to prevent built objects passed as parameters from being dynamically connected, since presumably the method/ctor being called will do whatever is needed (except for cherify, which wants its arg connected). Note that we can only catch those passed to cheri-invoked ctors/methods.

Defined Under Namespace

Classes: Conn

Instance Method Summary collapse

Constructor Details

#initializeConnectionMinder

:nodoc: all



639
640
641
642
643
# File 'lib/cheri/builder/context.rb', line 639

def initialize
  @c = {} # pending connections. indexed by builder.__id__
  #@a = {} # pending 'any' connections. indexed by builder.__id__
  @o = {} # pending builder(object)s. indexed by object.__id__
end

Instance Method Details

#ck(y, *r) ⇒ Object Also known as: check

check args passed to ctors/methods against the pending objects hash, and remove any matches from the pending connections/objects hashes.



689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
# File 'lib/cheri/builder/context.rb', line 689

def ck(y,*r)
  unless r.empty? || y == :cheri_yield || y == :cherify
    o = @o
    r.each do |a|
      if (b = o[a.__id__])
        cs = @c[b.__id__]
        cs.reverse_each do |c|
          if a.equal?(c.obj)
            cs.delete(c)
            o.delete(a.__id__)
          end
        end
      end
    end
    if Hash === r.last
      r.last.each_value do |a|
        if (b = o[a.__id__])
          cs = @c[b.__id__]
          cs.reverse_each do |c|
            if a.equal?(c.obj)
              cs.delete(c)
              o.delete(a.__id__)
            end
          end
        end
      end
    end     
  end
end

#po(b) ⇒ Object Also known as: popped

a builder has been popped from the stack. connect any pending (prepared) connections, and remove each builder/object associated with a connection from the pending objects hash.



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File 'lib/cheri/builder/context.rb', line 655

def po(b)
  if @a && (ac = @a.delete b.__id__)
    ac.each do |c|
      c.connect rescue nil
    end
  end
  if (cs = @c.delete b.__id__)
    begin
      cs.each do |c| c.connect; end
    ensure
      o = @o
      cs.each do |c| o.delete c.obj.__id__; end
    end    
  end
end

#ppd(ctr, bldr, obj, sym, props = nil) ⇒ Object Also known as: prepared

store a prepared connection.



673
674
675
676
677
# File 'lib/cheri/builder/context.rb', line 673

def ppd(ctr,bldr,obj,sym,props=nil)
  @o[obj.__id__] = bldr
  @c[bldr.__id__] << Conn.new(ctr,bldr.object,obj,sym,props)
  true
end

#ppda(ctr, bldr, obj, sym, props = nil) ⇒ Object Also known as: prepared_any

store a prepared ‘any’ connection.



681
682
683
684
# File 'lib/cheri/builder/context.rb', line 681

def ppda(ctr,bldr,obj,sym,props=nil)
  ((@a ||= {})[bldr.__id__] ||= []) << Conn.new(ctr,bldr.object,obj,sym,props)
  true
end

#pu(b) ⇒ Object Also known as: pushed

a builder has been pushed onto the stack. create an array to hold pending connections for that builder



647
648
649
# File 'lib/cheri/builder/context.rb', line 647

def pu(b)
  @c[b.__id__] = []
end