s2container 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1 +1,8 @@
1
- under construction
1
+
2
+ 2009-04-26 s2container-0.9.0
3
+
4
+ * add: destroy method to Seasar::Container::S2Container, Seasar::Container::ComponentDef.
5
+
6
+ 2009-04-15 s2container-0.8.0
7
+
8
+ * info: s2container-0.8.0 first release from rubyforge.
data/ChangeLog.ja CHANGED
@@ -1,5 +1,11 @@
1
1
 
2
+ 2009-04-15 s2container-0.8.0
3
+
4
+ * info: s2container-0.8.0 first release from rubyforge.
5
+ * info: 参照:ChangeLog.
6
+
2
7
  2009-04-11 s2container-0.8.0
8
+
3
9
  * modify: Seasar::Util::ClassUtilで、attribute accessor methodの取得時に親クラスのメソッドは探索しないようにしました。
4
10
  * modify: Seasar::Container::S2ApplicationContextをinstance化するように変更しました。
5
11
  * add: Seasar::Container::S2ApplicationContextにsnapshotメソッドを追加しました。
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- RUBY_S2CONTAINER_VERSION = '0.8.0'
1
+ RUBY_S2CONTAINER_VERSION = '0.9.0'
2
2
 
3
3
  require 'rubygems'
4
4
  require 'rake'
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  spec = Gem::Specification.new do |s|
20
20
  s.name = 's2container'
21
- s.date = '2009-04-01'
21
+ s.date = '2009-04-26'
22
22
  s.version = RUBY_S2CONTAINER_VERSION
23
23
  s.authors = ['klove']
24
24
  s.email = 'klovelion@gmail.com'
@@ -45,7 +45,6 @@ module Seasar
45
45
  def get_argument(component_key, is_array_acceptable = False)
46
46
  value = nil
47
47
  begin
48
- s2logger.fatal(self){ 'aaa ' + component_key.to_s}
49
48
  value = @component_def.container.get_component(component_key)
50
49
  rescue Seasar::Container::Exception::TooManyRegistrationRuntimeException => e
51
50
  if is_array_acceptable
@@ -45,8 +45,8 @@ module Seasar
45
45
  if @component_def.onetime_proc.is_a?(Proc)
46
46
  procedure = @component_def.onetime_proc
47
47
  @component_def.onetime_proc = nil
48
- elsif @component_def.procedure.is_a?(Proc)
49
- procedure = @component_def.procedure
48
+ elsif @component_def.constructor.is_a?(Proc)
49
+ procedure = @component_def.constructor
50
50
  end
51
51
  if procedure.nil?
52
52
  return @component_def.get_concreate_class.new(*args)
@@ -23,9 +23,9 @@ module Seasar
23
23
  # - args
24
24
  # 1. Class <em>component_class</em>
25
25
  # 2. String|Symbol <em>component_name</em>
26
- # 3. Proc <em>procedure</em>
27
- def initialize(component_class, component_name = nil, &procedure)
28
- @procedure = procedure
26
+ # 3. Proc <em>block</em>
27
+ def initialize(component_class, component_name = nil, &block)
28
+ @constructor = block
29
29
  @onetime_proc = nil
30
30
  @container = nil
31
31
  @component_class = component_class
@@ -39,7 +39,53 @@ module Seasar
39
39
  @autobinding_def = Seasar::Container::Assembler::AutoBindingDefFactory.get_autobinding_def(AutoBindingDef::AUTO_NAME)
40
40
  end
41
41
  attr_accessor :container, :component_class, :component_name, :instance_def, :autobinding_def
42
- attr_accessor :procedure, :onetime_proc
42
+ attr_accessor :constructor, :onetime_proc, :destructor
43
+
44
+ #
45
+ # - args
46
+ # 1. Proc|nil <em>block</em>
47
+ # - return
48
+ # - Proc
49
+ #
50
+ def constructor(&block)
51
+ if block
52
+ @constructor = block
53
+ end
54
+ return @constructor
55
+ end
56
+
57
+ #
58
+ # - args
59
+ # 1. Proc|nil <em>block</em>
60
+ # - return
61
+ # - Proc
62
+ #
63
+ def destructor(&block)
64
+ if block
65
+ @destructor = block
66
+ end
67
+ return @destructor
68
+ end
69
+
70
+ #
71
+ # - args
72
+ # - none
73
+ # - return
74
+ # - none
75
+ #
76
+ def init
77
+ return self.get_component_deployer.init
78
+ end
79
+
80
+ #
81
+ # - args
82
+ # - none
83
+ # - return
84
+ # - none
85
+ #
86
+ def destroy
87
+ return self.get_component_deployer.destroy
88
+ end
43
89
 
44
90
  #
45
91
  # - args
@@ -41,16 +41,43 @@ module Seasar
41
41
 
42
42
  # - args
43
43
  # 1. Hash <em>options</em>
44
- # 1. Proc <em>procedure</em>
45
- def initialize(options, &procedure)
44
+ # 1. Proc <em>block</em>
45
+ def initialize(options, &block)
46
46
  @component_class = options[:class]
47
47
  @component_name = options[:name]
48
48
  @instance = options[:instance]
49
49
  @autobinding = options[:autobinding]
50
50
  @namespace = options[:namespace]
51
- @procedure = procedure
51
+ @constructor = block
52
+ end
53
+ attr_accessor :component_class, :component_name, :instance, :autobinding, :namespace
54
+ attr_accessor :constructor, :destructor
55
+
56
+ #
57
+ # - args
58
+ # 1. Proc|nil <em>block</em>
59
+ # - return
60
+ # - Proc
61
+ #
62
+ def constructor(&block)
63
+ if block
64
+ @constructor = block
65
+ end
66
+ return @constructor
67
+ end
68
+
69
+ #
70
+ # - args
71
+ # 1. Proc|nil <em>block</em>
72
+ # - return
73
+ # - Proc
74
+ #
75
+ def destructor(&block)
76
+ if block
77
+ @destructor = block
78
+ end
79
+ return @destructor
52
80
  end
53
- attr_accessor :component_class, :component_name, :instance, :autobinding, :namespace, :procedure
54
81
 
55
82
  #
56
83
  # - args
@@ -104,14 +131,6 @@ module Seasar
104
131
  end
105
132
  end
106
133
 
107
- def ==(other)
108
- @component_class == other.component_class &&
109
- @component_name == other.component_name &&
110
- @instance == other.instance &&
111
- @autobinding == other.autobinding &&
112
- self.namespace() == other.namespace() &&
113
- @procedure == other.procedure
114
- end
115
134
  end
116
135
  end
117
136
  end
@@ -41,6 +41,20 @@ module Seasar
41
41
  @constructor_assembler = @component_def.autobinding_def.create_constructor_assembler(@component_def)
42
42
  @property_assembler = @component_def.autobinding_def.create_property_assembler(@component_def)
43
43
  end
44
+
45
+ # - args
46
+ # - none
47
+ # - return
48
+ # - none
49
+ def init
50
+ end
51
+
52
+ # - args
53
+ # - none
54
+ # - return
55
+ # - none
56
+ def destroy
57
+ end
44
58
  end
45
59
  end
46
60
  end
@@ -41,8 +41,8 @@ module Seasar
41
41
  end
42
42
  @instantiating = true
43
43
  component = @constructor_assembler.assemble
44
- @property_assembler.assemble(component)
45
44
  @instantiating = false
45
+ @property_assembler.assemble(component)
46
46
  return component
47
47
  end
48
48
  end
@@ -48,6 +48,26 @@ module Seasar
48
48
  end
49
49
  return @component
50
50
  end
51
+
52
+ # - args
53
+ # - none
54
+ # - return
55
+ # - none
56
+ def init
57
+ self.deploy
58
+ end
59
+
60
+ # - args
61
+ # - none
62
+ # - return
63
+ # - none
64
+ def destroy
65
+ return if @component.nil?
66
+ if @component_def.destructor
67
+ @component_def.destructor.call(@component)
68
+ end
69
+ @component = nil
70
+ end
51
71
  end
52
72
  end
53
73
  end
@@ -168,6 +168,7 @@ module Seasar
168
168
  else
169
169
  @component_infos << info
170
170
  end
171
+ return info
171
172
  end
172
173
 
173
174
  #
@@ -189,6 +190,7 @@ module Seasar
189
190
  else
190
191
  @aspect_infos << info
191
192
  end
193
+ return info
192
194
  end
193
195
  alias aspect register_aspect
194
196
 
@@ -250,18 +252,18 @@ module Seasar
250
252
  component_infos = self.get_component_infos(namespaces)
251
253
  component_infos = self.select_component_infos(component_infos, &procedure)
252
254
  component_infos.each {|component_info|
253
- if component_info.procedure.nil?
254
- cd = ComponentDef.new(component_info.component_class, component_info.component_name)
255
- else
256
- procedure = component_info.procedure
257
- cd = ComponentDef.new(component_info.component_class, component_info.component_name, &procedure)
258
- end
255
+ cd = ComponentDef.new(component_info.component_class, component_info.component_name)
256
+ cd.constructor = component_info.constructor
257
+ cd.destructor = component_info.destructor
258
+
259
259
  if not component_info.instance.nil?
260
260
  cd.instance_def = Seasar::Container::Deployer::InstanceDefFactory.get_instance_def(component_info.instance)
261
261
  end
262
+
262
263
  if not component_info.autobinding.nil?
263
264
  cd.autobinding_def = Seasar::Container::Assembler::AutoBindingDefFactory.get_autobinding_def(component_info.autobinding)
264
265
  end
266
+
265
267
  component_defs << cd
266
268
  if component_info.namespace.nil?
267
269
  container.register(cd)
@@ -36,6 +36,26 @@ module Seasar
36
36
  def get_container
37
37
  return @component
38
38
  end
39
+
40
+ #
41
+ # - args
42
+ # - none
43
+ # - return
44
+ # - none
45
+ #
46
+ def init
47
+ return self.get_container.init
48
+ end
49
+
50
+ #
51
+ # - args
52
+ # - none
53
+ # - return
54
+ # - none
55
+ #
56
+ def destroy
57
+ return self.get_container.destroy
58
+ end
39
59
  end
40
60
  end
41
61
  end
@@ -34,8 +34,36 @@ module Seasar
34
34
  @parents = []
35
35
  @children = []
36
36
  @namespace = nil
37
+ @inited = false;
38
+ end
39
+ attr_accessor :root, :parents, :namespace, :inited
40
+
41
+ #
42
+ # - args
43
+ # - none
44
+ # - return
45
+ # - Boolean
46
+ #
47
+ def init
48
+ return if @inited
49
+ @children.each {|child| child.init}
50
+ @component_def_list.each {|component_def| component_def.init}
51
+ @inited = true
52
+ return @inited
53
+ end
54
+
55
+ #
56
+ # - args
57
+ # - none
58
+ # - return
59
+ # - Boolean
60
+ #
61
+ def destroy
62
+ @component_def_list.reverse.each {|component_def| component_def.destroy}
63
+ @children.reverse.each {|child| child.destroy}
64
+ @inited = false
65
+ return @inited
37
66
  end
38
- attr_accessor :root, :parents, :namespace
39
67
 
40
68
  #
41
69
  # - args
@@ -148,6 +176,8 @@ module Seasar
148
176
  #
149
177
  # - args
150
178
  # 1. String|Symbol <em>key</em>
179
+ # 2. Boolean <em>search_parent</em>
180
+ # 3. Array <em>ignore_children</em>
151
181
  # - return
152
182
  # - Seasar::Container::ComponentDef
153
183
  #
@@ -40,6 +40,24 @@ module Seasar
40
40
  alias get get_component
41
41
  alias component get_component
42
42
  alias [] get_component
43
+
44
+ #
45
+ # - args
46
+ # - none
47
+ # - return
48
+ # - none
49
+ #
50
+ def init
51
+ end
52
+
53
+ #
54
+ # - args
55
+ # - none
56
+ # - return
57
+ # - none
58
+ #
59
+ def destroy
60
+ end
43
61
  end
44
62
  end
45
63
  end
@@ -50,7 +50,7 @@ def s2component(option = {}, &procedure)
50
50
  raise TypeError.new("class not specified.")
51
51
  end
52
52
  end
53
- s2app.register(option, &procedure)
53
+ return s2app.register(option, &procedure)
54
54
  end
55
55
  alias s2comp s2component
56
56
 
@@ -80,7 +80,7 @@ def s2aspect(option = {}, &procedure)
80
80
  option[:pattern] = self.name
81
81
  end
82
82
  end
83
- s2app.aspect(option, &procedure)
83
+ return s2app.aspect(option, &procedure)
84
84
  end
85
85
 
86
86
  #
@@ -16,7 +16,23 @@ module Seasar
16
16
  a1 = deployer.deploy
17
17
  assert_equal(a, a1)
18
18
  end
19
+
20
+ def test_destructor
21
+ cd = Seasar::Container::ComponentDef.new(A, "a")
22
+ cd.destructor {|component|
23
+ s2logger.debug(self.class){'destroy called. ' + component.to_s}
24
+ }
25
+ deployer = SingletonComponentDeployer.new(cd)
26
+ deployer.destroy
27
+
28
+ deployer.init
29
+ deployer.destroy
30
+ end
31
+
19
32
  class A
33
+ def to_s
34
+ return 'This is Class A.'
35
+ end
20
36
  end
21
37
  end
22
38
  end
@@ -63,7 +63,7 @@ module Seasar
63
63
  assert_equal(s2app.get(E).b, B)
64
64
  end
65
65
 
66
- def test_zzznamespaced_component
66
+ def test_namespaced_component
67
67
  s2app.init
68
68
  assert_equal(F, s2app.get(F).class)
69
69
  assert_equal(F, s2app.get(F, 'namespace_f').class)
@@ -146,7 +146,7 @@ module Seasar
146
146
  # d e f
147
147
  # g
148
148
  #
149
- def test_zzznamespace
149
+ def test_namespace
150
150
  a = S2Container.new
151
151
  a.namespace = 'a'
152
152
  cd = ComponentDef.new(A)
@@ -220,6 +220,34 @@ module Seasar
220
220
  assert(g.has_component_def('x.y.f.g.Gg'))
221
221
  end
222
222
 
223
+ def test_init_destroy
224
+ parent = S2Container.new
225
+ cd = ComponentDef.new(A)
226
+ cd.constructor {
227
+ s2logger.debug(self.class){'parent a inited.'}
228
+ A.new
229
+ }
230
+ cd.destructor {|component|
231
+ s2logger.debug(self.class){'parent a destoryed.'}
232
+ }
233
+ parent.register(cd)
234
+
235
+ child = S2Container.new
236
+ parent.include(child)
237
+ cd = ComponentDef.new(B)
238
+ cd.constructor {
239
+ s2logger.debug(self.class){'child b inited.'}
240
+ B.new
241
+ }
242
+ cd.destructor {|component|
243
+ s2logger.debug(self.class){'child b destoryed.'}
244
+ }
245
+ child.register(cd)
246
+
247
+ parent.init
248
+ parent.destroy
249
+ end
250
+
223
251
  class A
224
252
  def foo
225
253
  puts "foo called."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s2container
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - klove
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-01 00:00:00 +09:00
12
+ date: 2009-04-26 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15