needle 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/LICENSE-BSD +27 -0
- data/doc/LICENSE-GPL +280 -0
- data/doc/LICENSE-RUBY +56 -0
- data/doc/README +70 -0
- data/doc/manual/chapter.erb +18 -0
- data/doc/manual/index.erb +29 -0
- data/doc/manual/manual.css +192 -0
- data/doc/manual/manual.rb +240 -0
- data/doc/manual/manual.yml +48 -0
- data/doc/manual/page.erb +86 -0
- data/doc/manual/parts/01_license.txt +5 -0
- data/doc/manual/parts/01_support.txt +1 -0
- data/doc/manual/parts/01_use_cases.txt +141 -0
- data/doc/manual/parts/01_what_is_needle.txt +1 -0
- data/doc/manual/parts/02_creating.txt +9 -0
- data/doc/manual/parts/02_namespaces.txt +47 -0
- data/doc/manual/parts/02_overview.txt +3 -0
- data/doc/manual/parts/02_services.txt +44 -0
- data/doc/manual/tutorial.erb +30 -0
- data/doc/manual-html/chapter-1.html +354 -0
- data/doc/manual-html/chapter-2.html +310 -0
- data/doc/manual-html/chapter-3.html +154 -0
- data/doc/manual-html/chapter-4.html +154 -0
- data/doc/manual-html/chapter-5.html +154 -0
- data/doc/manual-html/chapter-6.html +154 -0
- data/doc/manual-html/chapter-7.html +154 -0
- data/doc/manual-html/index.html +177 -0
- data/doc/manual-html/manual.css +192 -0
- data/lib/needle/container.rb +318 -0
- data/lib/needle/errors.rb +32 -0
- data/lib/needle/include-exclude.rb +116 -0
- data/lib/needle/interceptor-chain.rb +162 -0
- data/lib/needle/interceptor.rb +189 -0
- data/lib/needle/log-factory.rb +207 -0
- data/lib/needle/logger.rb +161 -0
- data/lib/needle/logging-interceptor.rb +62 -0
- data/lib/needle/models/prototype-deferred.rb +41 -0
- data/lib/needle/models/prototype.rb +39 -0
- data/lib/needle/models/proxy.rb +84 -0
- data/lib/needle/models/singleton-deferred.rb +57 -0
- data/lib/needle/models/singleton.rb +56 -0
- data/lib/needle/models.rb +44 -0
- data/lib/needle/registry.rb +110 -0
- data/lib/needle/service-point.rb +109 -0
- data/lib/needle/version.rb +28 -0
- data/lib/needle.rb +54 -0
- data/test/ALL-TESTS.rb +21 -0
- data/test/models/tc_prototype.rb +53 -0
- data/test/models/tc_prototype_deferred.rb +54 -0
- data/test/models/tc_proxy.rb +51 -0
- data/test/models/tc_singleton.rb +53 -0
- data/test/models/tc_singleton_deferred.rb +54 -0
- data/test/tc_container.rb +246 -0
- data/test/tc_interceptor.rb +92 -0
- data/test/tc_interceptor_chain.rb +181 -0
- data/test/tc_logger.rb +181 -0
- data/test/tc_models.rb +44 -0
- data/test/tc_registry.rb +34 -0
- data/test/tc_service_point.rb +100 -0
- metadata +107 -0
data/test/tc_logger.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# This source file is distributed as part of the Needle dependency injection
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
|
10
|
+
# distribution for the texts of these licenses.
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# needle website : http://needle.rubyforge.org
|
13
|
+
# project website: http://rubyforge.org/projects/needle
|
14
|
+
# =============================================================================
|
15
|
+
#++
|
16
|
+
|
17
|
+
$:.unshift "../lib"
|
18
|
+
|
19
|
+
require 'needle/log-factory'
|
20
|
+
require 'test/unit'
|
21
|
+
require 'stringio'
|
22
|
+
|
23
|
+
class TC_Logger < Test::Unit::TestCase
|
24
|
+
|
25
|
+
class MockLogIO
|
26
|
+
attr_reader :message
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
clear
|
30
|
+
end
|
31
|
+
|
32
|
+
def write( message )
|
33
|
+
@message << message << "\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
def clear
|
37
|
+
@message = ""
|
38
|
+
end
|
39
|
+
|
40
|
+
def close
|
41
|
+
@message = "<closed>"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_log_filename
|
46
|
+
factory = Needle::LogFactory.new
|
47
|
+
assert_equal Needle::LogFactory::DEFAULT_LOG_FILENAME,
|
48
|
+
factory.device.filename
|
49
|
+
factory.close
|
50
|
+
assert factory.closed?
|
51
|
+
|
52
|
+
factory = Needle::LogFactory.new :filename => './sample.log'
|
53
|
+
assert_equal "./sample.log", factory.device.filename
|
54
|
+
factory.close
|
55
|
+
|
56
|
+
factory = Needle::LogFactory.new :device => STDOUT
|
57
|
+
assert_equal STDOUT, factory.device
|
58
|
+
factory.close
|
59
|
+
|
60
|
+
assert !STDOUT.closed?
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_log_options
|
64
|
+
factory = Needle::LogFactory.new :default_date_format => "%Y",
|
65
|
+
:default_level => Logger::FATAL
|
66
|
+
assert_equal "%Y", factory.default_date_format
|
67
|
+
assert_equal Logger::FATAL, factory.default_level
|
68
|
+
factory.close
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_log_get
|
72
|
+
factory = Needle::LogFactory.new
|
73
|
+
|
74
|
+
log1a = factory.get( "test.log1" )
|
75
|
+
log2 = factory.get( "test.log2" )
|
76
|
+
log1b = factory.get( "test.log1" )
|
77
|
+
|
78
|
+
assert_equal log1a.object_id, log1b.object_id
|
79
|
+
assert_not_equal log1a.object_id, log2.object_id
|
80
|
+
|
81
|
+
factory.close
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_log_write
|
85
|
+
io = MockLogIO.new
|
86
|
+
factory = Needle::LogFactory.new(
|
87
|
+
:device => io,
|
88
|
+
:levels => {
|
89
|
+
"test.*" => :INFO
|
90
|
+
} )
|
91
|
+
|
92
|
+
log = factory.get( "test.log1" )
|
93
|
+
|
94
|
+
# the factory has DEBUG turned off...
|
95
|
+
log.debug "test"
|
96
|
+
assert_equal "", io.message
|
97
|
+
|
98
|
+
log.info "test"
|
99
|
+
assert_match( /\[INFO \] .* -- test.log1: test/, io.message )
|
100
|
+
|
101
|
+
factory.close
|
102
|
+
assert_equal "<closed>", io.message
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_levels
|
106
|
+
io = MockLogIO.new
|
107
|
+
factory = Needle::LogFactory.new :device => io,
|
108
|
+
:levels => {
|
109
|
+
"level.*" => :WARN,
|
110
|
+
"level.test.*" => :DEBUG
|
111
|
+
}
|
112
|
+
|
113
|
+
log = factory.get( "level.log1" )
|
114
|
+
|
115
|
+
log.info "test"
|
116
|
+
assert_equal "", io.message
|
117
|
+
|
118
|
+
log = factory.get( "level.test.log1" )
|
119
|
+
|
120
|
+
log.debug "test"
|
121
|
+
assert_match( /\[DEBUG\] .* -- level.test.log1: test/, io.message )
|
122
|
+
|
123
|
+
factory.close
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_message_format
|
127
|
+
io = MockLogIO.new
|
128
|
+
factory = Needle::LogFactory.new :device => io,
|
129
|
+
:default_message_format => "%c %C [%-5p] %F %m %M %t %% %$"
|
130
|
+
|
131
|
+
log = factory.get( "message.log1" )
|
132
|
+
log.info "test"
|
133
|
+
assert_match(
|
134
|
+
/log1 message.log1 \[INFO \] \S*tc_logger.rb test test_message_format #{Thread.current.__id__} % #{$$}\n/,
|
135
|
+
io.message
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_logger_write_to
|
140
|
+
io = StringIO.new
|
141
|
+
io2 = StringIO.new
|
142
|
+
|
143
|
+
factory = Needle::LogFactory.new :device => io,
|
144
|
+
:default_message_format => "%m"
|
145
|
+
|
146
|
+
log = factory.get( "test.write-to" )
|
147
|
+
log.info "test"
|
148
|
+
log.info "another"
|
149
|
+
assert_match( /\Atest\nanother/, io.string )
|
150
|
+
|
151
|
+
log.write_to io2
|
152
|
+
log.info "howdy"
|
153
|
+
assert_match( /\Atest/, io.string )
|
154
|
+
assert_match( /\Ahowdy/, io2.string )
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_log_factory_write_to
|
158
|
+
io = StringIO.new
|
159
|
+
io2 = StringIO.new
|
160
|
+
|
161
|
+
factory = Needle::LogFactory.new :device => io,
|
162
|
+
:default_message_format => "%m"
|
163
|
+
|
164
|
+
log1 = factory.get( "test.write-to" )
|
165
|
+
log2 = factory.get( "test.write-to2" )
|
166
|
+
|
167
|
+
log1.info "test"
|
168
|
+
log2.info "another"
|
169
|
+
|
170
|
+
assert_match( /\Atest\nanother/, io.string )
|
171
|
+
|
172
|
+
factory.write_to io2
|
173
|
+
assert io.closed?
|
174
|
+
|
175
|
+
log1.info "howdy"
|
176
|
+
log2.info "world"
|
177
|
+
|
178
|
+
assert_match( /\Ahowdy\nworld/, io2.string )
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
data/test/tc_models.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# This source file is distributed as part of the Needle dependency injection
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
|
10
|
+
# distribution for the texts of these licenses.
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# needle website : http://needle.rubyforge.org
|
13
|
+
# project website: http://rubyforge.org/projects/needle
|
14
|
+
# =============================================================================
|
15
|
+
#++
|
16
|
+
|
17
|
+
$:.unshift "../lib"
|
18
|
+
|
19
|
+
require 'needle/models'
|
20
|
+
require 'test/unit'
|
21
|
+
|
22
|
+
class TC_Models < Test::Unit::TestCase
|
23
|
+
|
24
|
+
class Registry < Hash
|
25
|
+
def register( name, opts={}, &callback )
|
26
|
+
self[name] = callback.call( self )
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_register
|
31
|
+
registry = Registry.new
|
32
|
+
|
33
|
+
Needle::Models.register( registry )
|
34
|
+
assert_equal 1, registry.length
|
35
|
+
assert registry.has_key?( :service_models )
|
36
|
+
|
37
|
+
models = registry[:service_models]
|
38
|
+
|
39
|
+
assert_equal 4, models.length
|
40
|
+
assert_equal [:prototype, :prototype_deferred, :singleton, :singleton_deferred],
|
41
|
+
models.keys.sort {|a,b| a.to_s <=> b.to_s}
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/test/tc_registry.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# This source file is distributed as part of the Needle dependency injection
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
|
10
|
+
# distribution for the texts of these licenses.
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# needle website : http://needle.rubyforge.org
|
13
|
+
# project website: http://rubyforge.org/projects/needle
|
14
|
+
# =============================================================================
|
15
|
+
#++
|
16
|
+
|
17
|
+
$:.unshift "../lib"
|
18
|
+
|
19
|
+
require 'needle/registry'
|
20
|
+
require 'test/unit'
|
21
|
+
|
22
|
+
class TC_Registry < Test::Unit::TestCase
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@registry = Needle::Registry.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_bootstrap
|
29
|
+
assert_respond_to @registry, :service_models
|
30
|
+
assert_instance_of Hash, @registry.service_models
|
31
|
+
assert_equal 4, @registry.service_models.length
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# This source file is distributed as part of the Needle dependency injection
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
|
10
|
+
# distribution for the texts of these licenses.
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# needle website : http://needle.rubyforge.org
|
13
|
+
# project website: http://rubyforge.org/projects/needle
|
14
|
+
# =============================================================================
|
15
|
+
#++
|
16
|
+
|
17
|
+
$:.unshift "../lib"
|
18
|
+
|
19
|
+
require 'needle/interceptor'
|
20
|
+
require 'needle/service-point'
|
21
|
+
require 'test/unit'
|
22
|
+
|
23
|
+
class TC_ServicePoint < Test::Unit::TestCase
|
24
|
+
|
25
|
+
class Model
|
26
|
+
def initialize(container,opts={},&callback)
|
27
|
+
@callback = callback
|
28
|
+
end
|
29
|
+
def instance
|
30
|
+
@callback.call
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Container
|
35
|
+
def root
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def service_models
|
40
|
+
{ :mock => Model }
|
41
|
+
end
|
42
|
+
|
43
|
+
def fullname
|
44
|
+
"container"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Interceptor
|
49
|
+
def initialize( point, opts )
|
50
|
+
end
|
51
|
+
def process( chain, context )
|
52
|
+
chain.process_next( context )
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup
|
57
|
+
@container = Container.new
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_initialize
|
61
|
+
point = nil
|
62
|
+
|
63
|
+
assert_nothing_raised do
|
64
|
+
point =
|
65
|
+
Needle::ServicePoint.new( @container, "test", :model => :mock ) {
|
66
|
+
Hash.new }
|
67
|
+
end
|
68
|
+
|
69
|
+
assert_equal "test", point.name
|
70
|
+
assert_equal "container.test", point.fullname
|
71
|
+
|
72
|
+
assert_nothing_raised do
|
73
|
+
point =
|
74
|
+
Needle::ServicePoint.new( @container, "test", :model => Model ) {
|
75
|
+
Hash.new }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_instance
|
80
|
+
point =
|
81
|
+
Needle::ServicePoint.new( @container, "test", :model => :mock ) {
|
82
|
+
Hash.new }
|
83
|
+
|
84
|
+
inst = point.instance
|
85
|
+
assert_instance_of Hash, inst
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_interceptor
|
89
|
+
point =
|
90
|
+
Needle::ServicePoint.new( @container, "test", :model => :mock ) {
|
91
|
+
Hash.new }
|
92
|
+
|
93
|
+
interceptor = Needle::Interceptor.new.with { Interceptor }
|
94
|
+
point.interceptor interceptor
|
95
|
+
|
96
|
+
inst = point.instance
|
97
|
+
assert_instance_of Needle::InterceptorChainBuilder::InterceptedServiceProxy, inst
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.1
|
3
|
+
specification_version: 1
|
4
|
+
name: needle
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.5.0
|
7
|
+
date: 2004-10-14
|
8
|
+
summary: Needle is a Dependency Injection/Inversion of Control container for Ruby. It supports both type-2 (setter) and type-3 (constructor) injection. It takes advantage of the dynamic nature of Ruby to provide a rich and flexible approach to injecting dependencies.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
author: Jamis Buck
|
12
|
+
email: jgb3@email.byu.edu
|
13
|
+
homepage: http://needle.rubyforge.org
|
14
|
+
rubyforge_project:
|
15
|
+
description:
|
16
|
+
autorequire: needle
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: true
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
-
|
23
|
+
- ">"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.0.0
|
26
|
+
version:
|
27
|
+
platform: ruby
|
28
|
+
files:
|
29
|
+
- doc/README
|
30
|
+
- doc/LICENSE-RUBY
|
31
|
+
- doc/manual-html
|
32
|
+
- doc/LICENSE-BSD
|
33
|
+
- doc/LICENSE-GPL
|
34
|
+
- doc/manual
|
35
|
+
- doc/manual-html/manual.css
|
36
|
+
- doc/manual-html/chapter-1.html
|
37
|
+
- doc/manual-html/chapter-2.html
|
38
|
+
- doc/manual-html/chapter-3.html
|
39
|
+
- doc/manual-html/chapter-4.html
|
40
|
+
- doc/manual-html/chapter-5.html
|
41
|
+
- doc/manual-html/chapter-6.html
|
42
|
+
- doc/manual-html/chapter-7.html
|
43
|
+
- doc/manual-html/index.html
|
44
|
+
- doc/manual/img
|
45
|
+
- doc/manual/manual.css
|
46
|
+
- doc/manual/manual.yml
|
47
|
+
- doc/manual/tutorial.erb
|
48
|
+
- doc/manual/parts
|
49
|
+
- doc/manual/chapter.erb
|
50
|
+
- doc/manual/page.erb
|
51
|
+
- doc/manual/index.erb
|
52
|
+
- doc/manual/manual.rb
|
53
|
+
- doc/manual/parts/02_namespaces.txt
|
54
|
+
- doc/manual/parts/01_support.txt
|
55
|
+
- doc/manual/parts/02_services.txt
|
56
|
+
- doc/manual/parts/01_what_is_needle.txt
|
57
|
+
- doc/manual/parts/02_creating.txt
|
58
|
+
- doc/manual/parts/01_license.txt
|
59
|
+
- doc/manual/parts/01_use_cases.txt
|
60
|
+
- doc/manual/parts/02_overview.txt
|
61
|
+
- lib/needle.rb
|
62
|
+
- lib/needle
|
63
|
+
- lib/needle/interceptor.rb
|
64
|
+
- lib/needle/service-point.rb
|
65
|
+
- lib/needle/logger.rb
|
66
|
+
- lib/needle/models.rb
|
67
|
+
- lib/needle/registry.rb
|
68
|
+
- lib/needle/interceptor-chain.rb
|
69
|
+
- lib/needle/models
|
70
|
+
- lib/needle/include-exclude.rb
|
71
|
+
- lib/needle/container.rb
|
72
|
+
- lib/needle/logging-interceptor.rb
|
73
|
+
- lib/needle/version.rb
|
74
|
+
- lib/needle/log-factory.rb
|
75
|
+
- lib/needle/errors.rb
|
76
|
+
- lib/needle/models/prototype.rb
|
77
|
+
- lib/needle/models/singleton.rb
|
78
|
+
- lib/needle/models/singleton-deferred.rb
|
79
|
+
- lib/needle/models/prototype-deferred.rb
|
80
|
+
- lib/needle/models/proxy.rb
|
81
|
+
- test/tc_service_point.rb
|
82
|
+
- test/tc_registry.rb
|
83
|
+
- test/tc_interceptor.rb
|
84
|
+
- test/ALL-TESTS.rb
|
85
|
+
- test/models
|
86
|
+
- test/tc_interceptor_chain.rb
|
87
|
+
- test/tc_logger.rb
|
88
|
+
- test/tc_models.rb
|
89
|
+
- test/tc_container.rb
|
90
|
+
- test/models/tc_prototype.rb
|
91
|
+
- test/models/tc_singleton.rb
|
92
|
+
- test/models/tc_singleton_deferred.rb
|
93
|
+
- test/models/tc_prototype_deferred.rb
|
94
|
+
- test/models/tc_proxy.rb
|
95
|
+
test_files:
|
96
|
+
- test/ALL-TESTS.rb
|
97
|
+
rdoc_options:
|
98
|
+
- "--title"
|
99
|
+
- "Needle -- Dependency Injection for Ruby"
|
100
|
+
- "--main"
|
101
|
+
- doc/README
|
102
|
+
extra_rdoc_files:
|
103
|
+
- doc/README
|
104
|
+
executables: []
|
105
|
+
extensions: []
|
106
|
+
requirements: []
|
107
|
+
dependencies: []
|