hypo 0.9.0 → 0.10.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
- SHA1:
3
- metadata.gz: 30f40875e20a502201a114102dd727b8d978f4c4
4
- data.tar.gz: a3b2d46e45b7bba05b2ba5e74e6e724e99acef2a
2
+ SHA256:
3
+ metadata.gz: 616f20c6f5918ef12b8f4e9581a7bb9fc4d914f3b3f1792be6f10b26b16f6e9c
4
+ data.tar.gz: 99a09c150f54245ed18008ec71d5855a4e04528eb1ddff8d590d2ee09dce8230
5
5
  SHA512:
6
- metadata.gz: dadd3621cf8ba7aac482e3827df70f2619310740e40d3bb1bc78101194e1920c45a80b726cbbcff9e341c02b4ea3635b8e62cbe2b248ef45ccbef3872a57e40e
7
- data.tar.gz: f0d0de29132a087e26f908b4cffbed452970a4fdaca9c1f897b7aaaf8700caa88eaca5f45e657e28dfba834a4372fd48c5d2d114f75154b0fcd3dfba0166f20c
6
+ metadata.gz: e8ad659d399c93a45734d62b5635bdf8593c79d9a76352241332a6e2087ba09f2dcaae41b5c3e2b94f1584f728d66fa10141cfd64d8a8e1ad13db69035e69a28
7
+ data.tar.gz: 7f4100718ca23c6145a5998ccb7668eef46035730db5a8c20448f59c2ed8120ff2db87464bf3caa4badfba617d42d949da0cd9c934f2bec3905cc58a7ca8695c
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Hypo ![Build Status](https://travis-ci.org/cylon-v/hypo.svg)
1
+ # Hypo ![Build Status](https://travis-ci.org/cylon-v/hypo.svg?branch=master)
2
2
  Hypo is sinless general purpose IoC container for Ruby applications.
3
3
 
4
4
  ## Installation
@@ -14,11 +14,13 @@ module Hypo
14
14
  @type = type
15
15
  @name = name || type.name.gsub(/(.)([A-Z](?=[a-z]))/, '\1_\2').delete('::').downcase.to_sym
16
16
  @lifetime = container.lifetimes[:transient]
17
- @dependency_names = @type.instance_method(:initialize).parameters.map {|p| p[1]}
17
+ @dependency_names = @type.instance_method(:initialize).parameters
18
+ .map{|p| p[1]}
19
+ .select{|name| ![:attrs, :attributes].include?(name)}
18
20
  end
19
21
 
20
- def instance
21
- instance = @lifetime.instance(self)
22
+ def instance(attrs = {})
23
+ instance = @lifetime.instance(self, attrs)
22
24
 
23
25
  @dependency_names.each do |dependency|
24
26
  instance.instance_variable_set "@#{dependency}".to_sym, @container.resolve(dependency)
@@ -48,15 +48,14 @@ module Hypo
48
48
  @components[name]
49
49
  end
50
50
 
51
- def resolve(name)
51
+ def resolve(name, attrs = nil)
52
52
  if [:attrs, :attributes].include? name
53
- {}
54
53
  else
55
54
  unless @components.key?(name)
56
55
  raise ContainerError, "Component with name \"#{name}\" is not registered"
57
56
  end
58
57
 
59
- @components[name].instance
58
+ @components[name].instance(attrs)
60
59
  end
61
60
  end
62
61
 
@@ -17,7 +17,7 @@ module Hypo
17
17
  @name = name
18
18
  end
19
19
 
20
- def instance
20
+ def instance(attrs = nil)
21
21
  @lifetime.instance(self)
22
22
  end
23
23
  end
@@ -1,12 +1,13 @@
1
1
  module Hypo
2
2
  module Lifetime
3
3
  class Scope
4
- def instance(component)
4
+ def instance(component, attrs = nil)
5
5
  instances = component.scope.instances
6
6
 
7
7
  unless instances.key? component.name
8
8
  if component.respond_to? :type
9
- instances[component.name] = component.type.new(*component.dependencies)
9
+ dependencies = attrs ? [attrs].concat(component.dependencies) : component.dependencies
10
+ instances[component.name] = component.type.new(*dependencies)
10
11
  else
11
12
  instances[component.name] = component.object
12
13
  end
@@ -6,7 +6,7 @@ module Hypo
6
6
  @mutex = Mutex.new
7
7
  end
8
8
 
9
- def instance(component)
9
+ def instance(component, attrs = nil)
10
10
  @instances[component.name]
11
11
  end
12
12
 
@@ -1,9 +1,10 @@
1
1
  module Hypo
2
2
  module Lifetime
3
3
  class Transient
4
- def instance(component)
4
+ def instance(component, attrs = nil)
5
5
  if component.respond_to? :type
6
- component.type.new(*component.dependencies)
6
+ dependencies = attrs ? [attrs].concat(component.dependencies) : component.dependencies
7
+ component.type.new(*dependencies)
7
8
  else
8
9
  component.object
9
10
  end
@@ -1,3 +1,3 @@
1
1
  module Hypo
2
- VERSION = '0.9.0'
2
+ VERSION = '0.10.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.9.0
4
+ version: 0.10.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: 2018-04-12 00:00:00.000000000 Z
11
+ date: 2018-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.6.12
105
+ rubygems_version: 2.7.7
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Hypo is sinless general purpose IoC container