hypo 0.5.2 → 0.5.3

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: 11b617d07d312984ef5942f39710c8485a96f81b
4
- data.tar.gz: 9c1f1b23dc86f54612c4f2d5f14c0cae5c808fc9
3
+ metadata.gz: 8614f91194399e30161b6760806d78022b77cf08
4
+ data.tar.gz: 84ecd96dac8d1d9be247a2ea75474e9495fcec76
5
5
  SHA512:
6
- metadata.gz: 940a6fa8eee66b8ea88cf87f65d4eeaded5072daf75fca8496bad2a86f11038a13f87950702fc65a5ce50494085f47d6fbae20c0597787e8a4a006998f9a878a
7
- data.tar.gz: 497f31732dce3870a86870460e6bf181dde6fa2756145a5b848f9f8b39a32bd055a2b23fb9af0346345e573c301520cdaf85a0bcb93361309b6eef0c8aa90cce
6
+ metadata.gz: e591d6ee14c72335d913d968f9dd8a380cedb902a6dd2b791b9631a2cd23c8ccece718b6a0799fb779d6500749d701e0faa7dca080047455db36c67f997b9ae2
7
+ data.tar.gz: 12e0efe7253eb3eb2a4d979a99f79136a3564dde9d3814f43b347e877c1e1d82bbb743656e48c8e2785c0ae51b30a1acbcd3985a15279a6ecd80de4a0b64ecd5
data/README.md CHANGED
@@ -65,7 +65,7 @@ and if you registered both of them, you can do:
65
65
  Sometimes you're not able to manage a type lifecycle, i.e. when you use 3rd-party static stuff, like:
66
66
  ```ruby
67
67
  class DB
68
- def connect
68
+ def self.connect
69
69
  # ...
70
70
  end
71
71
  end
@@ -86,7 +86,7 @@ Out of the box Hypo provides Hypo::Singleton strategy, you can use it when regis
86
86
  ```ruby
87
87
  container.register(User).using_life_cycle(Hypo::Singleton)
88
88
  ```
89
- Actually you can implement you own life cycle,
89
+ Actually you can implement your own life cycle,
90
90
  i.e. makes sense to think about HttpRequest strategy for your web applications.
91
91
 
92
92
  ## Development
@@ -0,0 +1,7 @@
1
+ module Hypo
2
+ module Chainable
3
+ def register(item, name = nil)
4
+ @container.register(item, name)
5
+ end
6
+ end
7
+ end
@@ -1,27 +1,38 @@
1
1
  require 'hypo/life_cycle/transient'
2
+ require 'hypo/chainable'
2
3
 
3
4
  module Hypo
4
5
  class Component
6
+ include Chainable
7
+
5
8
  attr_reader :name, :type, :container, :life_cycle
6
9
 
7
10
  def initialize(type, container, name = nil)
8
11
  @container = container
9
- @life_cycle = Transient.new(self)
10
-
11
12
  @type = type
12
13
  @name = name || type.name.gsub(/(.)([A-Z](?=[a-z]))/, '\1_\2').delete('::').downcase.to_sym
14
+ @life_cycle = Transient.new(self)
15
+ @dependency_names = @type.instance_method(:initialize).parameters.map {|p| p[1]}
13
16
  end
14
17
 
15
18
  def instance
16
- @life_cycle.instance
19
+ instance = @life_cycle.instance
20
+
21
+ @dependency_names.each do |dependency|
22
+ instance.instance_variable_set "@#{dependency}".to_sym, @container.resolve(dependency)
23
+ end
24
+
25
+ instance
17
26
  end
18
27
 
19
28
  def dependencies
20
- @type.instance_method(:initialize).parameters.map { |p| @container.resolve(p[1]) }
29
+ @dependency_names.map { |dependency| @container.resolve(dependency) }
21
30
  end
22
31
 
23
32
  def use_life_cycle(life_cycle)
24
33
  @life_cycle = life_cycle.new(self)
34
+
35
+ self
25
36
  end
26
37
 
27
38
  alias using_life_cycle use_life_cycle
@@ -6,6 +6,7 @@ module Hypo
6
6
  class Container
7
7
  def initialize
8
8
  @components = {}
9
+ register self, :container
9
10
  end
10
11
 
11
12
  def register(item, name = nil)
data/lib/hypo/instance.rb CHANGED
@@ -1,6 +1,10 @@
1
+ require 'hypo/chainable'
2
+
1
3
  module Hypo
2
4
  class Instance
3
- attr_reader :name
5
+ include Chainable
6
+
7
+ attr_reader :name, :container
4
8
 
5
9
  def initialize(object, container, name)
6
10
  raise ContainerError, 'Registered object should have a name' if name.nil?
data/lib/hypo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hypo
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
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.5.2
4
+ version: 0.5.3
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-09-04 00:00:00.000000000 Z
11
+ date: 2017-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,7 @@ files:
70
70
  - bin/setup
71
71
  - hypo.gemspec
72
72
  - lib/hypo.rb
73
+ - lib/hypo/chainable.rb
73
74
  - lib/hypo/component.rb
74
75
  - lib/hypo/container.rb
75
76
  - lib/hypo/container_error.rb