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:



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, 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:



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

#_poolObject



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_keysObject



140
141
142
# File 'lib/when_exe/parts/resource.rb', line 140

def pool_keys
  _pool.keys
end