hypo 0.9.0 → 1.0.2

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: f7386bb66f974939ca93a451031711da913c59f87cf2ffc9977ce1cf119c1a70
4
+ data.tar.gz: 434e8e4f4a2a7d133ff79b6ffa9ec2acfd1c29db33f334d2fa9cdfd70fe75fca
5
5
  SHA512:
6
- metadata.gz: dadd3621cf8ba7aac482e3827df70f2619310740e40d3bb1bc78101194e1920c45a80b726cbbcff9e341c02b4ea3635b8e62cbe2b248ef45ccbef3872a57e40e
7
- data.tar.gz: f0d0de29132a087e26f908b4cffbed452970a4fdaca9c1f897b7aaaf8700caa88eaca5f45e657e28dfba834a4372fd48c5d2d114f75154b0fcd3dfba0166f20c
6
+ metadata.gz: 1d0a7182cd2889eb10c1087acda2b2267b1f1e561b19f41562d54170567d4092a099ae00c161d61f967fcd6b022470ca831e5fdb039ce31915bfe52bf0588a92
7
+ data.tar.gz: 667389b3df96f03c499204cd8c6536a680eb6d392ddf99d46a6ddcc4c6ba397f2e952415a9c4c01526cf848658ff4070bada98745485a0a1731c002b94755c0a
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
data/hypo.gemspec CHANGED
@@ -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
data/lib/hypo/instance.rb CHANGED
@@ -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
data/lib/hypo/scope.rb CHANGED
@@ -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
data/lib/hypo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hypo
2
- VERSION = '0.9.0'
2
+ VERSION = '1.0.2'
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: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kalinkin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-12 00:00:00.000000000 Z
11
+ date: 2021-06-26 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
@@ -86,7 +87,7 @@ licenses:
86
87
  - MIT
87
88
  metadata:
88
89
  allowed_push_host: https://rubygems.org
89
- post_install_message:
90
+ post_install_message:
90
91
  rdoc_options: []
91
92
  require_paths:
92
93
  - lib
@@ -101,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  - !ruby/object:Gem::Version
102
103
  version: '0'
103
104
  requirements: []
104
- rubyforge_project:
105
- rubygems_version: 2.6.12
106
- signing_key:
105
+ rubygems_version: 3.2.15
106
+ signing_key:
107
107
  specification_version: 4
108
108
  summary: Hypo is sinless general purpose IoC container
109
109
  test_files: []