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
オブジェクト参照
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/when_exe/parts/resource.rb', line 106 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 を登録する
134 135 136 137 |
# File 'lib/when_exe/parts/resource.rb', line 134 def []=(label, obj) # raise NameError, "Name duplication" if (@_pool[label]) _pool[label] = obj end |
#_pool ⇒ Object
145 146 147 148 |
# File 'lib/when_exe/parts/resource.rb', line 145 def _pool _setup_ unless @_pool @_pool end |
#_setup_ ⇒ void
This method returns an undefined value.
初期化
93 94 95 96 97 98 |
# File 'lib/when_exe/parts/resource.rb', line 93 def _setup_ @_lock_ = Mutex.new if When.multi_thread @_lock_.lock if @_lock_ @_pool = {} @_lock_.unlock if @_lock_ end |
#pool_keys ⇒ Object
140 141 142 |
# File 'lib/when_exe/parts/resource.rb', line 140 def pool_keys _pool.keys end |