hypo 0.5.1 → 0.5.2
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.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/hypo/component.rb +7 -7
- data/lib/hypo/{life_style → life_cycle}/singleton.rb +0 -0
- data/lib/hypo/{life_style → life_cycle}/transient.rb +0 -0
- data/lib/hypo/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11b617d07d312984ef5942f39710c8485a96f81b
|
4
|
+
data.tar.gz: 9c1f1b23dc86f54612c4f2d5f14c0cae5c808fc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 940a6fa8eee66b8ea88cf87f65d4eeaded5072daf75fca8496bad2a86f11038a13f87950702fc65a5ce50494085f47d6fbae20c0597787e8a4a006998f9a878a
|
7
|
+
data.tar.gz: 497f31732dce3870a86870460e6bf181dde6fa2756145a5b848f9f8b39a32bd055a2b23fb9af0346345e573c301520cdaf85a0bcb93361309b6eef0c8aa90cce
|
data/README.md
CHANGED
@@ -77,16 +77,16 @@ container.register(connection, :connection)
|
|
77
77
|
```
|
78
78
|
You must specify component name as it's done in example above.
|
79
79
|
|
80
|
-
## Component
|
81
|
-
By default all registered components have
|
80
|
+
## Component Life Cycle
|
81
|
+
By default all registered components have life cycle Hypo::Transient.
|
82
82
|
It means, every time when you resolve a component Hypo returns new instance of its type.
|
83
83
|
If you wanna change this behavior then you can replace lifetime strategy.
|
84
84
|
Out of the box Hypo provides Hypo::Singleton strategy, you can use it when register a component:
|
85
85
|
|
86
86
|
```ruby
|
87
|
-
container.register(User).
|
87
|
+
container.register(User).using_life_cycle(Hypo::Singleton)
|
88
88
|
```
|
89
|
-
Actually you can implement you own
|
89
|
+
Actually you can implement you 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,29 +1,29 @@
|
|
1
|
-
require 'hypo/
|
1
|
+
require 'hypo/life_cycle/transient'
|
2
2
|
|
3
3
|
module Hypo
|
4
4
|
class Component
|
5
|
-
attr_reader :name, :type, :container, :
|
5
|
+
attr_reader :name, :type, :container, :life_cycle
|
6
6
|
|
7
7
|
def initialize(type, container, name = nil)
|
8
8
|
@container = container
|
9
|
-
@
|
9
|
+
@life_cycle = Transient.new(self)
|
10
10
|
|
11
11
|
@type = type
|
12
12
|
@name = name || type.name.gsub(/(.)([A-Z](?=[a-z]))/, '\1_\2').delete('::').downcase.to_sym
|
13
13
|
end
|
14
14
|
|
15
15
|
def instance
|
16
|
-
@
|
16
|
+
@life_cycle.instance
|
17
17
|
end
|
18
18
|
|
19
19
|
def dependencies
|
20
20
|
@type.instance_method(:initialize).parameters.map { |p| @container.resolve(p[1]) }
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
@
|
23
|
+
def use_life_cycle(life_cycle)
|
24
|
+
@life_cycle = life_cycle.new(self)
|
25
25
|
end
|
26
26
|
|
27
|
-
alias
|
27
|
+
alias using_life_cycle use_life_cycle
|
28
28
|
end
|
29
29
|
end
|
File without changes
|
File without changes
|
data/lib/hypo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kalinkin
|
@@ -74,8 +74,8 @@ files:
|
|
74
74
|
- lib/hypo/container.rb
|
75
75
|
- lib/hypo/container_error.rb
|
76
76
|
- lib/hypo/instance.rb
|
77
|
-
- lib/hypo/
|
78
|
-
- lib/hypo/
|
77
|
+
- lib/hypo/life_cycle/singleton.rb
|
78
|
+
- lib/hypo/life_cycle/transient.rb
|
79
79
|
- lib/hypo/version.rb
|
80
80
|
homepage: https://github.com/cylon-v/hypo
|
81
81
|
licenses:
|