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
-
#[](label) ⇒ When::Parts::Resource
オブジェクト参照.
-
#[]=(label, obj) ⇒ void
オブジェクト登録.
- #_pool ⇒ Object
-
#_setup_ ⇒ void
初期化.
- #pool_keys ⇒ Object
Methods included from Synchronize
Instance Method Details
#[](label) ⇒ When::Parts::Resource
オブジェクト参照
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/when_exe/parts/resource.rb', line 81 def [](label) # nil label return _pool[label] unless label # 階層構造の確認 unless label =~ /\?/ terms = label.split(/::/) terms.shift if terms[0] == '' return terms.inject(self) {|obj,term| obj = obj[term]} if terms.length >= 2 end # 階層がない場合 path, = label.split(/\?/, 2) label = Resource._extract_prefix(path) label += '?' + if _pool[label.gsub(/%3A%3A/, '::')] end |
#[]=(label, obj) ⇒ void
This method returns an undefined value.
オブジェクト登録
指定した label で子 Resource を登録する
109 110 111 112 |
# File 'lib/when_exe/parts/resource.rb', line 109 def []=(label, obj) # raise NameError, "Name duplication" if (@_pool[label]) _pool[label] = obj end |
#_pool ⇒ Object
120 121 122 123 |
# File 'lib/when_exe/parts/resource.rb', line 120 def _pool _setup_ unless @_pool @_pool end |
#_setup_ ⇒ void
Note:
本メソッドでマルチスレッド対応の管理変数の初期化を行っている。このため、本メソッド自体はスレッドセーフでない。
This method returns an undefined value.
初期化
70 71 72 73 |
# File 'lib/when_exe/parts/resource.rb', line 70 def _setup_ @_lock_ = Mutex.new if When.multi_thread @_pool = {} end |
#pool_keys ⇒ Object
115 116 117 |
# File 'lib/when_exe/parts/resource.rb', line 115 def pool_keys _pool.keys end |