hypo 0.9.0 → 0.10.0
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/lib/hypo/component.rb +5 -3
- data/lib/hypo/container.rb +2 -3
- 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/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 616f20c6f5918ef12b8f4e9581a7bb9fc4d914f3b3f1792be6f10b26b16f6e9c
|
4
|
+
data.tar.gz: 99a09c150f54245ed18008ec71d5855a4e04528eb1ddff8d590d2ee09dce8230
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8ad659d399c93a45734d62b5635bdf8593c79d9a76352241332a6e2087ba09f2dcaae41b5c3e2b94f1584f728d66fa10141cfd64d8a8e1ad13db69035e69a28
|
7
|
+
data.tar.gz: 7f4100718ca23c6145a5998ccb7668eef46035730db5a8c20448f59c2ed8120ff2db87464bf3caa4badfba617d42d949da0cd9c934f2bec3905cc58a7ca8695c
|
data/README.md
CHANGED
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
@@ -48,15 +48,14 @@ module Hypo
|
|
48
48
|
@components[name]
|
49
49
|
end
|
50
50
|
|
51
|
-
def resolve(name)
|
51
|
+
def resolve(name, attrs = nil)
|
52
52
|
if [:attrs, :attributes].include? name
|
53
|
-
{}
|
54
53
|
else
|
55
54
|
unless @components.key?(name)
|
56
55
|
raise ContainerError, "Component with name \"#{name}\" is not registered"
|
57
56
|
end
|
58
57
|
|
59
|
-
@components[name].instance
|
58
|
+
@components[name].instance(attrs)
|
60
59
|
end
|
61
60
|
end
|
62
61
|
|
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
|
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: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kalinkin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.7.7
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Hypo is sinless general purpose IoC container
|