hypo 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/hypo/chainable.rb +7 -0
- data/lib/hypo/component.rb +15 -4
- data/lib/hypo/container.rb +1 -0
- data/lib/hypo/instance.rb +5 -1
- data/lib/hypo/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8614f91194399e30161b6760806d78022b77cf08
|
4
|
+
data.tar.gz: 84ecd96dac8d1d9be247a2ea75474e9495fcec76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e591d6ee14c72335d913d968f9dd8a380cedb902a6dd2b791b9631a2cd23c8ccece718b6a0799fb779d6500749d701e0faa7dca080047455db36c67f997b9ae2
|
7
|
+
data.tar.gz: 12e0efe7253eb3eb2a4d979a99f79136a3564dde9d3814f43b347e877c1e1d82bbb743656e48c8e2785c0ae51b30a1acbcd3985a15279a6ecd80de4a0b64ecd5
|
data/README.md
CHANGED
@@ -65,7 +65,7 @@ and if you registered both of them, you can do:
|
|
65
65
|
Sometimes you're not able to manage a type lifecycle, i.e. when you use 3rd-party static stuff, like:
|
66
66
|
```ruby
|
67
67
|
class DB
|
68
|
-
def connect
|
68
|
+
def self.connect
|
69
69
|
# ...
|
70
70
|
end
|
71
71
|
end
|
@@ -86,7 +86,7 @@ Out of the box Hypo provides Hypo::Singleton strategy, you can use it when regis
|
|
86
86
|
```ruby
|
87
87
|
container.register(User).using_life_cycle(Hypo::Singleton)
|
88
88
|
```
|
89
|
-
Actually you can implement
|
89
|
+
Actually you can implement your own life cycle,
|
90
90
|
i.e. makes sense to think about HttpRequest strategy for your web applications.
|
91
91
|
|
92
92
|
## Development
|
data/lib/hypo/component.rb
CHANGED
@@ -1,27 +1,38 @@
|
|
1
1
|
require 'hypo/life_cycle/transient'
|
2
|
+
require 'hypo/chainable'
|
2
3
|
|
3
4
|
module Hypo
|
4
5
|
class Component
|
6
|
+
include Chainable
|
7
|
+
|
5
8
|
attr_reader :name, :type, :container, :life_cycle
|
6
9
|
|
7
10
|
def initialize(type, container, name = nil)
|
8
11
|
@container = container
|
9
|
-
@life_cycle = Transient.new(self)
|
10
|
-
|
11
12
|
@type = type
|
12
13
|
@name = name || type.name.gsub(/(.)([A-Z](?=[a-z]))/, '\1_\2').delete('::').downcase.to_sym
|
14
|
+
@life_cycle = Transient.new(self)
|
15
|
+
@dependency_names = @type.instance_method(:initialize).parameters.map {|p| p[1]}
|
13
16
|
end
|
14
17
|
|
15
18
|
def instance
|
16
|
-
@life_cycle.instance
|
19
|
+
instance = @life_cycle.instance
|
20
|
+
|
21
|
+
@dependency_names.each do |dependency|
|
22
|
+
instance.instance_variable_set "@#{dependency}".to_sym, @container.resolve(dependency)
|
23
|
+
end
|
24
|
+
|
25
|
+
instance
|
17
26
|
end
|
18
27
|
|
19
28
|
def dependencies
|
20
|
-
@
|
29
|
+
@dependency_names.map { |dependency| @container.resolve(dependency) }
|
21
30
|
end
|
22
31
|
|
23
32
|
def use_life_cycle(life_cycle)
|
24
33
|
@life_cycle = life_cycle.new(self)
|
34
|
+
|
35
|
+
self
|
25
36
|
end
|
26
37
|
|
27
38
|
alias using_life_cycle use_life_cycle
|
data/lib/hypo/container.rb
CHANGED
data/lib/hypo/instance.rb
CHANGED
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.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kalinkin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- bin/setup
|
71
71
|
- hypo.gemspec
|
72
72
|
- lib/hypo.rb
|
73
|
+
- lib/hypo/chainable.rb
|
73
74
|
- lib/hypo/component.rb
|
74
75
|
- lib/hypo/container.rb
|
75
76
|
- lib/hypo/container_error.rb
|