Class: Cheri::Builder::InstanceContext

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

Constant Summary collapse

Col =
java.util.Collections
Map =
java.util.HashMap
WMap =
java.util.WeakHashMap

Instance Method Summary collapse

Constructor Details

#initialize(client, cfg) ⇒ InstanceContext

call-seq:

InstanceContext.new(client,builder_modules) -> anInstanceContext


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cheri/builder/context.rb', line 40

def initialize(client,cfg)
#    @c = client
  @g = cfg
  # TODO: properties, aliases should probably be threadsafe hashes/maps,
  # though contention would be extremely unlikely given expected usage (any
  # puts likely to be made on the instantiating thread, immediately
  # upon instantiation).
  @p = {} # properties
  @l = {} # aliases
  # TODO: find a better way to do this    
  if self.class.const_defined?("Map")
    @h = Col.synchronized_map WMap.new
    @t = true # use Thread as key
  else
    # TODO: should use weak hash here
    # TODO: threadsafe Ruby Hash implementation?
    @h = {}
  end
end

Instance Method Details

#[](k) ⇒ Object



89
90
91
# File 'lib/cheri/builder/context.rb', line 89

def [](k)
  @p[k]
end

#[]=(k, v) ⇒ Object



93
94
95
# File 'lib/cheri/builder/context.rb', line 93

def []=(k,v)
  @p[k] = v
end

#aliasesObject



97
98
99
# File 'lib/cheri/builder/context.rb', line 97

def aliases
  @l
end

#autoObject



68
69
70
# File 'lib/cheri/builder/context.rb', line 68

def auto
  @u
end

#auto!(m) ⇒ Object

Raises:

  • (BuilderException)


76
77
78
79
80
81
82
83
# File 'lib/cheri/builder/context.rb', line 76

def auto!(m)
  raise BuilderException,"not an included builder module: #{m}" unless @g.include?(m)
  if @u
    @u << m unless @u.include?(m)
  else
   @u = [m]
  end
end

#auto?(m) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/cheri/builder/context.rb', line 72

def auto?(m)
  @u && @u.include?(m)  
end

#cfgObject

def client

  @c  
end


64
65
66
# File 'lib/cheri/builder/context.rb', line 64

def cfg
  @g  
end

#currentObject

call-seq:

current -> context object for the current instance/thread


104
105
106
107
108
# File 'lib/cheri/builder/context.rb', line 104

def current
  key = @t ? Thread.current : Thread.current.__id__
  @h[key] ||= Context.new(self,@c)
#    Thread.current[:cheri_ctx] ||= Context.new(self,nil)
end

#inspectObject

Overrides the default Object#inspect to prevent mind-boggling circular displays in IRB.



111
112
113
# File 'lib/cheri/builder/context.rb', line 111

def inspect
  to_s 
end

#propsObject



85
86
87
# File 'lib/cheri/builder/context.rb', line 85

def props
  @p  
end