hypo 0.8.5 → 1.0.1

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: 61529acd6c0aeb0a50262343bb688744f99cca63
4
- data.tar.gz: 2748838e9f51a5e70cb40bf344f38e117f607e38
2
+ SHA256:
3
+ metadata.gz: d9b38a49c29061600e0ba7dde946282134acf5d7bd10b531a85fee00d7d9f0aa
4
+ data.tar.gz: e95c4e4379c7cffd46e2d17ea5a6a2b723644136c66b581c9dc5caad2b9d5a98
5
5
  SHA512:
6
- metadata.gz: e72939c09a42e8891d8e66cd0615b35ce0bf46084a3a571b69dd39cb2e6b610d439b160557d5e40b2d2a99a60f7153f9a3abfb6dfe2bf16c2c2ad0271c8adbfc
7
- data.tar.gz: 396d04654c549d0868705652e8ab3ab9148538829f9817db88297826a05995bdeb5807591863544f1e7299c78f79f0b9c43e32ba521789bfe31a2ccfb44e9e0d
6
+ metadata.gz: 51f36413062a97245a13ebddd9d6f6e8bf441e25fdda4dd360c1f6ba5be33ca036f98cf237d3212c92e25d1a5e6553adee11565f1d479529314859f10f11a8ee
7
+ data.tar.gz: b00ad79934cf20b624dd5d2c809ba9fb83ee806335ce601ab7a9fd705a5677b13a9451f1b98c35bfee8c92958e2f4028c8c928a57b24d708c6cb5ba9cd57cab7
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
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.required_ruby_version = '>= 2.0.0'
34
34
 
35
- spec.add_development_dependency 'bundler', '~> 1.15'
36
- spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'bundler', '~> 2.1'
36
+ spec.add_development_dependency 'rake', '~> 13.0'
37
37
  spec.add_development_dependency 'rspec', '~> 3.0'
38
38
  end
@@ -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)
@@ -1,4 +1,5 @@
1
1
  require 'hypo/container_error'
2
+ require 'hypo/missing_component_error'
2
3
  require 'hypo/component'
3
4
  require 'hypo/instance'
4
5
  require 'hypo/lifetime/transient'
@@ -48,15 +49,14 @@ module Hypo
48
49
  @components[name]
49
50
  end
50
51
 
51
- def resolve(name)
52
+ def resolve(name, attrs = nil)
52
53
  if [:attrs, :attributes].include? name
53
- {}
54
54
  else
55
55
  unless @components.key?(name)
56
- raise ContainerError, "Component with name \"#{name}\" is not registered"
56
+ raise MissingComponentError.new(name)
57
57
  end
58
58
 
59
- @components[name].instance
59
+ @components[name].instance(attrs)
60
60
  end
61
61
  end
62
62
 
@@ -65,5 +65,9 @@ module Hypo
65
65
 
66
66
  self
67
67
  end
68
+
69
+ def show(component_name)
70
+ @components[component_name]
71
+ end
68
72
  end
69
73
  end
@@ -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
@@ -0,0 +1,12 @@
1
+ module Hypo
2
+ class MissingComponentError < ContainerError
3
+ attr_reader :component_name
4
+
5
+ def initialize(component_name)
6
+ message = "Component with name \"#{component_name}\" is not registered"
7
+ super(message)
8
+
9
+ @component_name = component_name
10
+ end
11
+ end
12
+ end
@@ -7,11 +7,13 @@ module Hypo
7
7
  end
8
8
 
9
9
  def purge
10
- @instances.each_value do |instance|
11
- instance.finalize if instance.respond_to? :finalize
10
+ begin
11
+ @instances.each_value do |instance|
12
+ instance.finalize if instance.respond_to? :finalize
13
+ end
14
+ ensure
15
+ @instances = Hash.new
12
16
  end
13
-
14
- @instances = Hash.new
15
17
  end
16
18
  end
17
19
  end
@@ -1,3 +1,3 @@
1
1
  module Hypo
2
- VERSION = '0.8.5'
2
+ VERSION = '1.0.1'
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.8.5
4
+ version: 1.0.1
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-03-03 00:00:00.000000000 Z
11
+ date: 2020-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '2.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -78,6 +78,7 @@ files:
78
78
  - lib/hypo/lifetime/singleton.rb
79
79
  - lib/hypo/lifetime/transient.rb
80
80
  - lib/hypo/lifetime_friendly.rb
81
+ - lib/hypo/missing_component_error.rb
81
82
  - lib/hypo/scope.rb
82
83
  - lib/hypo/scope_friendly.rb
83
84
  - lib/hypo/version.rb
@@ -102,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  version: '0'
103
104
  requirements: []
104
105
  rubyforge_project:
105
- rubygems_version: 2.6.12
106
+ rubygems_version: 2.7.4
106
107
  signing_key:
107
108
  specification_version: 4
108
109
  summary: Hypo is sinless general purpose IoC container