hypo 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -3
  3. data/hypo.gemspec +2 -0
  4. data/lib/hypo/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35c57b5bdcc35e6e5360a56828c3a5eebb6d2dea
4
- data.tar.gz: d2baae541df45d07295d78ac3eda8425e7f358fd
3
+ metadata.gz: 6a568762c3ceb89a2a64afb118ee297054e9288a
4
+ data.tar.gz: e22d7dd48cea4a09f4d6bb6003045d39a8b6d505
5
5
  SHA512:
6
- metadata.gz: b663cc5597b98df87b3af69f86a7f44b0f83d72b9d25f66d3d945afdb1350a5241e1db57d1caf5a9982594c4ab267eab45963e9aac4a27713639314a246ea7ef
7
- data.tar.gz: b8189392738784f65b150ed1062a91b04da6421e8e976612f9b38074007c710d5ec90e307928404ae41a4e06fc1ebde615e40e7482fc43a88bd590eb4f8e4d69
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
- container = Hypo::Container.new
24
+ container = Hypo::Container.new
25
25
  ```
26
26
  Then you can register your types (classes) there:
27
27
  ```ruby
28
- container.register(User)
28
+ container.register(User)
29
29
  ```
30
30
  ..and resolve them:
31
31
  ```ruby
32
- container.resolve(:user)
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
@@ -1,3 +1,3 @@
1
1
  module Hypo
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
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.0
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: '0'
93
+ version: 2.0.0
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - ">="