hypo 0.8.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/hypo.gemspec +2 -2
- data/lib/hypo/component.rb +5 -3
- data/lib/hypo/container.rb +8 -4
- data/lib/hypo/instance.rb +1 -1
- data/lib/hypo/lifetime/scope.rb +3 -2
- data/lib/hypo/lifetime/singleton.rb +1 -1
- data/lib/hypo/lifetime/transient.rb +3 -2
- data/lib/hypo/missing_component_error.rb +12 -0
- data/lib/hypo/scope.rb +6 -4
- data/lib/hypo/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d9b38a49c29061600e0ba7dde946282134acf5d7bd10b531a85fee00d7d9f0aa
|
4
|
+
data.tar.gz: e95c4e4379c7cffd46e2d17ea5a6a2b723644136c66b581c9dc5caad2b9d5a98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51f36413062a97245a13ebddd9d6f6e8bf441e25fdda4dd360c1f6ba5be33ca036f98cf237d3212c92e25d1a5e6553adee11565f1d479529314859f10f11a8ee
|
7
|
+
data.tar.gz: b00ad79934cf20b624dd5d2c809ba9fb83ee806335ce601ab7a9fd705a5677b13a9451f1b98c35bfee8c92958e2f4028c8c928a57b24d708c6cb5ba9cd57cab7
|
data/README.md
CHANGED
data/hypo.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
spec.required_ruby_version = '>= 2.0.0'
|
34
34
|
|
35
|
-
spec.add_development_dependency 'bundler', '~> 1
|
36
|
-
spec.add_development_dependency 'rake', '~>
|
35
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
36
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
37
37
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
38
|
end
|
data/lib/hypo/component.rb
CHANGED
@@ -14,11 +14,13 @@ module Hypo
|
|
14
14
|
@type = type
|
15
15
|
@name = name || type.name.gsub(/(.)([A-Z](?=[a-z]))/, '\1_\2').delete('::').downcase.to_sym
|
16
16
|
@lifetime = container.lifetimes[:transient]
|
17
|
-
@dependency_names = @type.instance_method(:initialize).parameters
|
17
|
+
@dependency_names = @type.instance_method(:initialize).parameters
|
18
|
+
.map{|p| p[1]}
|
19
|
+
.select{|name| ![:attrs, :attributes].include?(name)}
|
18
20
|
end
|
19
21
|
|
20
|
-
def instance
|
21
|
-
instance = @lifetime.instance(self)
|
22
|
+
def instance(attrs = {})
|
23
|
+
instance = @lifetime.instance(self, attrs)
|
22
24
|
|
23
25
|
@dependency_names.each do |dependency|
|
24
26
|
instance.instance_variable_set "@#{dependency}".to_sym, @container.resolve(dependency)
|
data/lib/hypo/container.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'hypo/container_error'
|
2
|
+
require 'hypo/missing_component_error'
|
2
3
|
require 'hypo/component'
|
3
4
|
require 'hypo/instance'
|
4
5
|
require 'hypo/lifetime/transient'
|
@@ -48,15 +49,14 @@ module Hypo
|
|
48
49
|
@components[name]
|
49
50
|
end
|
50
51
|
|
51
|
-
def resolve(name)
|
52
|
+
def resolve(name, attrs = nil)
|
52
53
|
if [:attrs, :attributes].include? name
|
53
|
-
{}
|
54
54
|
else
|
55
55
|
unless @components.key?(name)
|
56
|
-
raise
|
56
|
+
raise MissingComponentError.new(name)
|
57
57
|
end
|
58
58
|
|
59
|
-
@components[name].instance
|
59
|
+
@components[name].instance(attrs)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -65,5 +65,9 @@ module Hypo
|
|
65
65
|
|
66
66
|
self
|
67
67
|
end
|
68
|
+
|
69
|
+
def show(component_name)
|
70
|
+
@components[component_name]
|
71
|
+
end
|
68
72
|
end
|
69
73
|
end
|
data/lib/hypo/instance.rb
CHANGED
data/lib/hypo/lifetime/scope.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Hypo
|
2
2
|
module Lifetime
|
3
3
|
class Scope
|
4
|
-
def instance(component)
|
4
|
+
def instance(component, attrs = nil)
|
5
5
|
instances = component.scope.instances
|
6
6
|
|
7
7
|
unless instances.key? component.name
|
8
8
|
if component.respond_to? :type
|
9
|
-
|
9
|
+
dependencies = attrs ? [attrs].concat(component.dependencies) : component.dependencies
|
10
|
+
instances[component.name] = component.type.new(*dependencies)
|
10
11
|
else
|
11
12
|
instances[component.name] = component.object
|
12
13
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Hypo
|
2
2
|
module Lifetime
|
3
3
|
class Transient
|
4
|
-
def instance(component)
|
4
|
+
def instance(component, attrs = nil)
|
5
5
|
if component.respond_to? :type
|
6
|
-
|
6
|
+
dependencies = attrs ? [attrs].concat(component.dependencies) : component.dependencies
|
7
|
+
component.type.new(*dependencies)
|
7
8
|
else
|
8
9
|
component.object
|
9
10
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Hypo
|
2
|
+
class MissingComponentError < ContainerError
|
3
|
+
attr_reader :component_name
|
4
|
+
|
5
|
+
def initialize(component_name)
|
6
|
+
message = "Component with name \"#{component_name}\" is not registered"
|
7
|
+
super(message)
|
8
|
+
|
9
|
+
@component_name = component_name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/hypo/scope.rb
CHANGED
@@ -7,11 +7,13 @@ module Hypo
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def purge
|
10
|
-
|
11
|
-
|
10
|
+
begin
|
11
|
+
@instances.each_value do |instance|
|
12
|
+
instance.finalize if instance.respond_to? :finalize
|
13
|
+
end
|
14
|
+
ensure
|
15
|
+
@instances = Hash.new
|
12
16
|
end
|
13
|
-
|
14
|
-
@instances = Hash.new
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
data/lib/hypo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hypo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kalinkin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/hypo/lifetime/singleton.rb
|
79
79
|
- lib/hypo/lifetime/transient.rb
|
80
80
|
- lib/hypo/lifetime_friendly.rb
|
81
|
+
- lib/hypo/missing_component_error.rb
|
81
82
|
- lib/hypo/scope.rb
|
82
83
|
- lib/hypo/scope_friendly.rb
|
83
84
|
- lib/hypo/version.rb
|
@@ -102,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
103
|
version: '0'
|
103
104
|
requirements: []
|
104
105
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.7.4
|
106
107
|
signing_key:
|
107
108
|
specification_version: 4
|
108
109
|
summary: Hypo is sinless general purpose IoC container
|