hypo 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -3
- data/hypo.gemspec +2 -0
- data/lib/hypo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a568762c3ceb89a2a64afb118ee297054e9288a
|
4
|
+
data.tar.gz: e22d7dd48cea4a09f4d6bb6003045d39a8b6d505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 696ad8bfc6f318a2a49de9516d17dd6dfb7ead86a68a400bff487bec442ee422ad12d2e884147b2c66d66b7cfcb863127ff8b1737550b4bc7d54aa1bf9747ab9
|
7
|
+
data.tar.gz: e989c62ad5192c8ddab75dbc1cf8bc7f1754216e7cfda1d4e9d548dfcd6176311a18c277377c46d62249b3a0ef3d7c03004acd1f1eacfd80364d3bf31e2d3194
|
data/README.md
CHANGED
@@ -21,16 +21,25 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
First of all you need to create an instance of Hypo::Container.
|
23
23
|
```ruby
|
24
|
-
|
24
|
+
container = Hypo::Container.new
|
25
25
|
```
|
26
26
|
Then you can register your types (classes) there:
|
27
27
|
```ruby
|
28
|
-
|
28
|
+
container.register(User)
|
29
29
|
```
|
30
30
|
..and resolve them:
|
31
31
|
```ruby
|
32
|
-
|
32
|
+
container.resolve(:user)
|
33
33
|
```
|
34
|
+
Optionally you can specify custom name for your component:
|
35
|
+
```ruby
|
36
|
+
container.register(User, :my_dear_user)
|
37
|
+
```
|
38
|
+
and then you can resolve the component as :my_dear_user:
|
39
|
+
```ruby
|
40
|
+
container.resolve(:my_dear_user)
|
41
|
+
```
|
42
|
+
|
34
43
|
Registered types can have some dependencies that will be resolved automatically if they're registered in the container. For example, you have classes:
|
35
44
|
|
36
45
|
```ruby
|
@@ -53,6 +62,21 @@ and if you registered both of them, you can do:
|
|
53
62
|
# user.company is resolved as well
|
54
63
|
```
|
55
64
|
|
65
|
+
Sometimes you're not able to manage a type lifecycle, i.e. when you use 3rd-party static stuff, like:
|
66
|
+
```ruby
|
67
|
+
class DB
|
68
|
+
def connect
|
69
|
+
# ...
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
73
|
+
In that case you can register an instance instead of a type:
|
74
|
+
```ruby
|
75
|
+
connection = DB.connect
|
76
|
+
container.register(connection, :connection)
|
77
|
+
```
|
78
|
+
You must specify component name as it's done in example above.
|
79
|
+
|
56
80
|
## Component Lifetime
|
57
81
|
By default all registered components have lifestyle Hypo::Transient.
|
58
82
|
It means, every time when you resolve a component Hypo returns new instance of its type.
|
data/hypo.gemspec
CHANGED
@@ -30,6 +30,8 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ['lib']
|
32
32
|
|
33
|
+
spec.required_ruby_version = '>= 2.0.0'
|
34
|
+
|
33
35
|
spec.add_development_dependency 'bundler', '~> 1.15'
|
34
36
|
spec.add_development_dependency 'rake', '~> 10.0'
|
35
37
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kalinkin
|
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
90
|
requirements:
|
91
91
|
- - ">="
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
93
|
+
version: 2.0.0
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
96
|
- - ">="
|