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:



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, options = label.split(/\?/, 2)
  label  = Resource._extract_prefix(path)
  label += '?' + options if options
  _pool[label.gsub(/%3A%3A/, '::')]
end

#[]=(label, obj) ⇒ void

This method returns an undefined value.

オブジェクト登録

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

Parameters:



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

#_poolObject



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_keysObject



115
116
117
# File 'lib/when_exe/parts/resource.rb', line 115

def pool_keys
  _pool.keys
end