Module: When::Parts::Resource::Pool

Includes:
Synchronize
Included in:
When::Parts::Resource, Timezone, TM::CalendarEra, TM::Clock, V::Event, V::Timezone
Defined in:
lib/when_exe/parts/resource.rb

Overview

Resource の has-a 親子関係を管理する

Instance Method Summary collapse

Methods included from Synchronize

#synchronize

Instance Method Details

#[](label) ⇒ When::Parts::Resource

オブジェクト参照

Parameters:

Returns:



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/when_exe/parts/resource.rb', line 98

def [](label)

  # nil label の場合
  return _pool[label] unless label

  # 階層がある場合
  terms = Resource._encode(label).split(/::/)
  terms.shift if terms[0] == ''
  return terms.inject(self) {|obj,term| obj = obj[Resource._decode(term)]} if terms.length >= 2

  # 階層がない場合
  _pool[Resource._decode(Resource._extract_prefix(terms[0]))]
end

#[]=(label, obj) ⇒ void

This method returns an undefined value.

オブジェクト登録

指定した label で子 Resource を登録する

Parameters:



121
122
123
124
# File 'lib/when_exe/parts/resource.rb', line 121

def []=(label, obj)
  # raise NameError, "Name duplication" if (@_pool[label])
  _pool[label] = obj
end

#_poolObject



132
133
134
135
# File 'lib/when_exe/parts/resource.rb', line 132

def _pool
  _setup_ unless @_pool
  @_pool
end

#_setup_void

Note:

本メソッドでマルチスレッド対応の管理変数の初期化を行っている。 このため、本メソッド自体はスレッドセーフでない。

This method returns an undefined value.

初期化



87
88
89
90
# File 'lib/when_exe/parts/resource.rb', line 87

def _setup_
  @_lock_ = Mutex.new if When.multi_thread
  @_pool  = {}
end

#pool_keysObject



127
128
129
# File 'lib/when_exe/parts/resource.rb', line 127

def pool_keys
  _pool.keys
end