hypo 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/README.md +32 -0
- data/lib/hypo/component.rb +2 -2
- data/lib/hypo/container.rb +2 -2
- 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: c013df3b3209930f2bf4dd5a0c1b59c66b0f52f8
|
4
|
+
data.tar.gz: 72a5542b3f2993539df0d08cd0f0eee12365c7ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0141b660aa08e573ea7b397b58fd3ba61b16fd6aaf856f08d2e23bb1c9e8c340b0970ddb65c529882104239229ace596a2dc3ad02c31ed31dca3b4551c3e0bb5
|
7
|
+
data.tar.gz: 38b2512a45a22eebc92eaddc07aeca23d1e053a88c6b518d35001b578ea668b7d95626bfada76cbd2c98470d0b7be1bb027faf3a13081f4822dbb5fed4ac5d9b
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,39 @@ Or install it yourself as:
|
|
18
18
|
$ gem install hypo
|
19
19
|
|
20
20
|
## Usage
|
21
|
+
First of all you need to create an instance of Hypo::Container.
|
22
|
+
```ruby
|
23
|
+
container = Hypo::Container.new
|
24
|
+
```
|
25
|
+
Then you can register your types (classes) there:
|
26
|
+
```ruby
|
27
|
+
container.register(User)
|
28
|
+
```
|
29
|
+
..and resolve them:
|
30
|
+
```ruby
|
31
|
+
container.resolve(:user)
|
32
|
+
```
|
33
|
+
Registered types can have some dependencies that will be resolved automatically if they're registered in the container. For example, you have classes:
|
21
34
|
|
35
|
+
```ruby
|
36
|
+
class User
|
37
|
+
attr_reader :company
|
38
|
+
def initialize(company)
|
39
|
+
@company = company
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Company
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
and if you registered both of them, you can do:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
user = container.resolve(:user)
|
51
|
+
|
52
|
+
# user.company is resolved as well
|
53
|
+
```
|
22
54
|
|
23
55
|
## Development
|
24
56
|
|
data/lib/hypo/component.rb
CHANGED
@@ -2,9 +2,9 @@ module Hypo
|
|
2
2
|
class Component
|
3
3
|
attr_reader :name, :type
|
4
4
|
|
5
|
-
def initialize(type, container)
|
5
|
+
def initialize(type, container, name = nil)
|
6
6
|
@type = type
|
7
|
-
@name = type.name.gsub(/(.)([A-Z](?=[a-z]))/,'\1_\2').delete('::').downcase.to_sym
|
7
|
+
@name = name || type.name.gsub(/(.)([A-Z](?=[a-z]))/,'\1_\2').delete('::').downcase.to_sym
|
8
8
|
@container = container
|
9
9
|
end
|
10
10
|
|
data/lib/hypo/container.rb
CHANGED
@@ -7,8 +7,8 @@ module Hypo
|
|
7
7
|
@components = {}
|
8
8
|
end
|
9
9
|
|
10
|
-
def register(type)
|
11
|
-
component = Component.new(type, self)
|
10
|
+
def register(type, name = nil)
|
11
|
+
component = Component.new(type, self, name)
|
12
12
|
if @components.key?(component.name)
|
13
13
|
raise ContainerError, "Component of type \"#{component.type.to_s}\" has already been registered"
|
14
14
|
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.3.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: 2017-
|
11
|
+
date: 2017-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.6.
|
98
|
+
rubygems_version: 2.6.12
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: Hypo is sinless general purpose IoC container
|