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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39500b4a91ded208c5e5e3dd500ad0674beddad7
4
- data.tar.gz: 9b459fced3ea79aab42de5e1e2f5cdd434d0a593
3
+ metadata.gz: c013df3b3209930f2bf4dd5a0c1b59c66b0f52f8
4
+ data.tar.gz: 72a5542b3f2993539df0d08cd0f0eee12365c7ad
5
5
  SHA512:
6
- metadata.gz: '0580af25ab52adb27af93106bed71282011e204ab28ca45f66e3fb0c4d49baeb89a23461e5737db5aa70af95858d4789ec9907a6211719a43e9684d07ff7d382'
7
- data.tar.gz: 2cdfbb3239ed2f698851de036326d6ad9ec54a90bb49d0b9ee0b4715d7a7de0def94e82d1adda62103c0d84b9d7324d80d293f1f842639001c3ea84cf21ea50e
6
+ metadata.gz: 0141b660aa08e573ea7b397b58fd3ba61b16fd6aaf856f08d2e23bb1c9e8c340b0970ddb65c529882104239229ace596a2dc3ad02c31ed31dca3b4551c3e0bb5
7
+ data.tar.gz: 38b2512a45a22eebc92eaddc07aeca23d1e053a88c6b518d35001b578ea668b7d95626bfada76cbd2c98470d0b7be1bb027faf3a13081f4822dbb5fed4ac5d9b
data/.gitignore CHANGED
@@ -11,7 +11,7 @@
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
13
  .idea
14
- .gem
14
+ *.gem
15
15
  .ruby-version
16
16
  .ruby-gemset
17
17
  coverage
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
 
@@ -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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Hypo
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.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-08-31 00:00:00.000000000 Z
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.13
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