Class: Seasar::Container::S2Container
- Inherits:
-
Object
- Object
- Seasar::Container::S2Container
- Defined in:
- lib/seasar/container/s2container.rb
Instance Attribute Summary collapse
-
#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
-
#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, ignore_children = []) ⇒ Object
-
args 1.
-
-
#get_component_def_internal(key, search_parent = true, ignore_children = []) ⇒ 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.
-
-
#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 |
# 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 end |
Instance Attribute Details
#namespace ⇒ Object
Returns the value of attribute namespace.
38 39 40 |
# File 'lib/seasar/container/s2container.rb', line 38 def namespace @namespace end |
#parents ⇒ Object
Returns the value of attribute parents.
38 39 40 |
# File 'lib/seasar/container/s2container.rb', line 38 def parents @parents end |
#root ⇒ Object
Returns the value of attribute root.
38 39 40 |
# File 'lib/seasar/container/s2container.rb', line 38 def root @root end |
Instance Method Details
#find_component_defs(key) ⇒ Object
-
args
-
String|Symbol key
-
-
return
-
Array
-
241 242 243 244 245 246 247 248 |
# File 'lib/seasar/container/s2container.rb', line 241 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
-
226 227 228 229 230 231 232 233 |
# File 'lib/seasar/container/s2container.rb', line 226 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
-
119 120 121 122 123 |
# File 'lib/seasar/container/s2container.rb', line 119 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
-
134 135 136 137 138 139 140 |
# File 'lib/seasar/container/s2container.rb', line 134 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, ignore_children = []) ⇒ Object
-
args
-
String|Symbol key
-
-
return
-
Seasar::Container::ComponentDef
-
200 201 202 203 204 205 206 207 |
# File 'lib/seasar/container/s2container.rb', line 200 def get_component_def_from_children(key, ignore_children = []) @children.each {|child_container| next if ignore_children.member?(child_container) component_def = child_container.get_component_def_internal(key, false) return component_def unless component_def.nil? } return nil end |
#get_component_def_internal(key, search_parent = true, ignore_children = []) ⇒ Object
ComponentDefをkeyで検索して返します。見つからなければnilが返ります。
keyがclassの場合は、自分自身が保持しているかを検索して、すべての子のコンテナ
に問い合わせます。keyが文字列の場合は、「.」区切りになっている場合は、namespace
で指定されたコンテナ以下のすべての子コンテナ内でComponentDefを検索します。
その後、見つからない場合は、自分自身が保持しているすべての子コンテナを検索します。
-
args
-
String|Symbol key
-
-
return
-
Seasar::Container::ComponentDef
-
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/seasar/container/s2container.rb', line 154 def get_component_def_internal(key, search_parent = true, ignore_children = []) 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, ignore_children) return component_def unless component_def.nil? end return nil unless search_parent ignore_children << self return nil if @parents.size == 0 @parents.each {|parent| next if parent.parents.size == 0 && ignore_children.member?(parent) component_def = parent.get_component_def_internal(key, true, ignore_children) return component_def unless component_def.nil? } return nil end |
#get_component_def_size ⇒ Object
-
args
-
none
-
-
return
-
Integer
-
108 109 110 |
# File 'lib/seasar/container/s2container.rb', line 108 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
-
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/seasar/container/s2container.rb', line 182 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
-
215 216 217 |
# File 'lib/seasar/container/s2container.rb', line 215 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
-
256 257 258 259 260 261 262 263 264 |
# File 'lib/seasar/container/s2container.rb', line 256 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 |
#inject(instance) ⇒ Object
-
args
-
Object instance
-
-
return
-
Seasar::Container::Assembler::AbstractAssembler
-
283 284 285 286 |
# File 'lib/seasar/container/s2container.rb', line 283 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
-
295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/seasar/container/s2container.rb', line 295 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
-
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/seasar/container/s2container.rb', line 47 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
-
68 69 70 71 72 73 |
# File 'lib/seasar/container/s2container.rb', line 68 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
-
81 82 83 84 85 |
# File 'lib/seasar/container/s2container.rb', line 81 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
-
94 95 96 97 98 99 100 |
# File 'lib/seasar/container/s2container.rb', line 94 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 |