Class: Seasar::Container::S2Container
- Inherits:
-
Object
- Object
- Seasar::Container::S2Container
- Defined in:
- lib/seasar/container/s2container.rb
Instance Attribute Summary collapse
-
#inited ⇒ Object
Returns the value of attribute inited.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#parents ⇒ Object
Returns the value of attribute parents.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#destroy ⇒ Object
-
args - none - return - Boolean.
-
-
#find_component_defs(key) ⇒ Object
-
args 1.
-
-
#find_components(key) ⇒ Object
-
args 1.
-
-
#get_component(key, &procedure) ⇒ Object
(also: #component, #get, #[])
-
args 1.
-
-
#get_component_def(key) ⇒ Object
(also: #component_def)
-
args 1.
-
-
#get_component_def_from_children(key, searched_as_parent = [], searched_as_child = []) ⇒ Object
-
args 1.
-
-
#get_component_def_internal(key, search_parent = true, searched_as_parent = [], searched_as_child = []) ⇒ Object
ComponentDefをkeyで検索して返します。見つからなければnilが返ります。 keyがclassの場合は、自分自身が保持しているかを検索して、すべての子のコンテナ に問い合わせます。keyが文字列の場合は、「.」区切りになっている場合は、namespace で指定されたコンテナ以下のすべての子コンテナ内でComponentDefを検索します。 その後、見つからない場合は、自分自身が保持しているすべての子コンテナを検索します。.
-
#get_component_def_size ⇒ Object
-
args - none - return - Integer.
-
-
#get_component_def_with_namespace(key) ⇒ Object
-
args 1.
-
-
#has_component_def(key) ⇒ Object
(also: #component_def?)
-
args 1.
-
-
#include(child_container) ⇒ Object
-
args 1.
-
-
#init ⇒ Object
-
args - none - return - Boolean.
-
-
#initialize ⇒ S2Container
constructor
-
args - none.
-
-
#inject(instance) ⇒ Object
-
args 1.
-
-
#process_toomany_registration(key, new_component_def) ⇒ Object
-
args 1.
-
-
#register(item, name = nil) ⇒ Object
-
args 1.
-
-
#register_by_class(component_def) ⇒ Object
-
args 1.
-
-
#register_by_name(component_def) ⇒ Object
-
args 1.
-
-
#register_map(key, component_def) ⇒ Object
-
args 1.
-
Constructor Details
#initialize ⇒ S2Container
-
args
-
none
-
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/seasar/container/s2container.rb', line 25 def initialize @component_def_list = [] @component_def_map = {} @outer_component_def = Seasar::Container::OuterComponentDef.new(self) component_def = SimpleComponentDef.new(self, 's2container') @component_def_map['container'] = component_def @component_def_map[:container] = component_def @component_def_map[self.class] = component_def @root = self @parents = [] @children = [] @namespace = nil @inited = false; end |
Instance Attribute Details
#inited ⇒ Object
Returns the value of attribute inited.
39 40 41 |
# File 'lib/seasar/container/s2container.rb', line 39 def inited @inited end |
#namespace ⇒ Object
Returns the value of attribute namespace.
39 40 41 |
# File 'lib/seasar/container/s2container.rb', line 39 def namespace @namespace end |
#parents ⇒ Object
Returns the value of attribute parents.
39 40 41 |
# File 'lib/seasar/container/s2container.rb', line 39 def parents @parents end |
#root ⇒ Object
Returns the value of attribute root.
39 40 41 |
# File 'lib/seasar/container/s2container.rb', line 39 def root @root end |
Instance Method Details
#destroy ⇒ Object
-
args
-
none
-
-
return
-
Boolean
-
61 62 63 64 65 66 |
# File 'lib/seasar/container/s2container.rb', line 61 def destroy @component_def_list.reverse.each {|component_def| component_def.destroy} @children.reverse.each {|child| child.destroy} @inited = false return @inited end |
#find_component_defs(key) ⇒ Object
-
args
-
String|Symbol key
-
-
return
-
Array
-
275 276 277 278 279 280 281 282 |
# File 'lib/seasar/container/s2container.rb', line 275 def find_component_defs(key) component_def = self.get_component_def(key) if component_def.instance_of?(Seasar::Container::TooManyRegistrationComponentDef) return component_def.component_defs else return [component_def] end end |
#find_components(key) ⇒ Object
-
args
-
String|Symbol key
-
-
return
-
Array
-
260 261 262 263 264 265 266 267 |
# File 'lib/seasar/container/s2container.rb', line 260 def find_components(key) component_defs = self.find_component_defs(key) components = [] for component_def in component_defs components << component_def.component end return components end |
#get_component(key, &procedure) ⇒ Object Also known as: component, get, []
-
args
-
String|Symbol key
-
Proc procedure
-
-
return
-
Object
-
147 148 149 150 151 |
# File 'lib/seasar/container/s2container.rb', line 147 def get_component(key, &procedure) cd = self.get_component_def(key) cd.onetime_proc = procedure return cd.get_component end |
#get_component_def(key) ⇒ Object Also known as: component_def
-
args
-
String|Symbol key
-
-
return
-
Seasar::Container::ComponentDef
-
162 163 164 165 166 167 168 |
# File 'lib/seasar/container/s2container.rb', line 162 def get_component_def(key) component_def = self.get_component_def_internal(key); if component_def.nil? raise Seasar::Container::Exception::ComponentNotFoundRuntimeException.new(key) end return component_def end |
#get_component_def_from_children(key, searched_as_parent = [], searched_as_child = []) ⇒ Object
-
args
-
String|Symbol key
-
-
return
-
Seasar::Container::ComponentDef
-
231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/seasar/container/s2container.rb', line 231 def get_component_def_from_children(key, searched_as_parent = [], searched_as_child = []) @children.each {|child_container| next if searched_as_parent.member?(child_container) next if searched_as_child.member?(child_container) #s2logger.debug(self.class.name){'search child container : ' + child_container.namespace.to_s} component_def = child_container.get_component_def_internal(key, false, searched_as_parent, searched_as_child) return component_def unless component_def.nil? searched_as_child << child_container } return nil end |
#get_component_def_internal(key, search_parent = true, searched_as_parent = [], searched_as_child = []) ⇒ Object
ComponentDefをkeyで検索して返します。見つからなければnilが返ります。
keyがclassの場合は、自分自身が保持しているかを検索して、すべての子のコンテナ
に問い合わせます。keyが文字列の場合は、「.」区切りになっている場合は、namespace
で指定されたコンテナ以下のすべての子コンテナ内でComponentDefを検索します。
その後、見つからない場合は、自分自身が保持しているすべての子コンテナを検索します。
-
args
-
String|Symbol key
-
Boolean search_parent
-
Array searched_as_parent
-
-
return
-
Seasar::Container::ComponentDef
-
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/seasar/container/s2container.rb', line 184 def get_component_def_internal(key, search_parent = true, searched_as_parent = [], searched_as_child = []) if @component_def_map.key?(key) return @component_def_map[key] elsif key.is_a?(String) && key.match(/\./) component_def = self.get_component_def_with_namespace(key) return component_def unless component_def.nil? else component_def = self.get_component_def_from_children(key, searched_as_parent, searched_as_child) return component_def unless component_def.nil? end return nil unless search_parent searched_as_parent << self return nil if @parents.size == 0 @parents.each {|parent| next if searched_as_parent.member?(parent) #s2logger.debug(self.class.name){'search parent container : ' + parent.namespace.to_s} component_def = parent.get_component_def_internal(key, true, searched_as_parent, searched_as_child) return component_def unless component_def.nil? } return nil end |
#get_component_def_size ⇒ Object
-
args
-
none
-
-
return
-
Integer
-
136 137 138 |
# File 'lib/seasar/container/s2container.rb', line 136 def get_component_def_size return @component_def_list.length end |
#get_component_def_with_namespace(key) ⇒ Object
-
args
-
String|Symbol key
-
-
return
-
Seasar::Container::ComponentDef
-
213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/seasar/container/s2container.rb', line 213 def get_component_def_with_namespace(key) if /^(.+?)\.(.+)$/ =~ key component_def = self.get_component_def_internal($1, false) unless component_def.nil? child_container = component_def.get_component() component_def = child_container.get_component_def_internal($2, false) return component_def unless component_def.nil? end end return nil end |
#has_component_def(key) ⇒ Object Also known as: component_def?
-
args
-
String|Symbol key
-
-
return
-
Boolean
-
249 250 251 |
# File 'lib/seasar/container/s2container.rb', line 249 def has_component_def(key) return self.get_component_def_internal(key).nil? == false end |
#include(child_container) ⇒ Object
-
args
-
Seasar::Container::S2Container child_container
-
-
return
-
none
-
290 291 292 293 294 295 296 297 298 |
# File 'lib/seasar/container/s2container.rb', line 290 def include(child_container) child_container.root = @root child_container.parents << self @children << child_container namespace = child_container.namespace if not namespace.nil? self.register_map(namespace, S2ContainerComponentDef.new(child_container, namespace)) end end |
#init ⇒ Object
-
args
-
none
-
-
return
-
Boolean
-
47 48 49 50 51 52 53 |
# File 'lib/seasar/container/s2container.rb', line 47 def init return if @inited @children.each {|child| child.init} @component_def_list.each {|component_def| component_def.init} @inited = true return @inited end |
#inject(instance) ⇒ Object
-
args
-
Object instance
-
-
return
-
Seasar::Container::Assembler::AbstractAssembler
-
317 318 319 320 |
# File 'lib/seasar/container/s2container.rb', line 317 def inject(instance) @outer_component_def.instance = instance return @outer_component_def.component end |
#process_toomany_registration(key, new_component_def) ⇒ Object
-
args
-
String|Symbol key
-
Seasar::Container::ComponentDef component_def
-
-
return
-
none
-
329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/seasar/container/s2container.rb', line 329 def process_toomany_registration(key, new_component_def) component_def = @component_def_map[key] if component_def.instance_of?(Seasar::Container::TooManyRegistrationComponentDef) component_def.add_component_def(new_component_def) else tmrcf = Seasar::Container::TooManyRegistrationComponentDef.new(key) tmrcf.add_component_def(component_def) tmrcf.add_component_def(new_component_def) @component_def_map[key] = tmrcf end end |
#register(item, name = nil) ⇒ Object
-
args
-
Object|Seasar::Container::ComponentDef item
-
String|Symbol name
-
-
return
-
none
-
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/seasar/container/s2container.rb', line 75 def register(item, name = nil) if item.is_a?(ComponentDef) component_def = item elsif item.class == Class return self.register(ComponentDef.new(item, name)) else component_def = SimpleComponentDef.new(item) end component_def.container = self if component_def.container.nil? @component_def_list << component_def self.register_by_name(component_def) self.register_by_class(component_def) end |
#register_by_class(component_def) ⇒ Object
-
args
-
Seasar::Container::ComponentDef component_def
-
-
return
-
none
-
96 97 98 99 100 101 |
# File 'lib/seasar/container/s2container.rb', line 96 def register_by_class(component_def) component_def.component_class.ancestors.each {|base| next if (base == Object or base == Kernel) self.register_map(base, component_def) } end |
#register_by_name(component_def) ⇒ Object
-
args
-
Seasar::Container::ComponentDef component_def
-
-
return
-
none
-
109 110 111 112 113 |
# File 'lib/seasar/container/s2container.rb', line 109 def register_by_name(component_def) if not component_def.component_name.nil? self.register_map(component_def.component_name, component_def) end end |
#register_map(key, component_def) ⇒ Object
-
args
-
String|Symbol key
-
Seasar::Container::ComponentDef component_def
-
-
return
-
none
-
122 123 124 125 126 127 128 |
# File 'lib/seasar/container/s2container.rb', line 122 def register_map(key, component_def) if @component_def_map.key?(key) self.process_toomany_registration(key, component_def) else @component_def_map[key] = component_def end end |