hypo 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.travis.yml +1 -0
- data/Gemfile +1 -0
- data/README.md +2 -2
- data/Rakefile +2 -2
- data/lib/hypo/component.rb +5 -3
- data/lib/hypo/container.rb +10 -3
- data/lib/hypo/container_error.rb +7 -0
- data/lib/hypo/version.rb +1 -1
- metadata +4 -4
- data/lib/hypo/resolving_error.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39500b4a91ded208c5e5e3dd500ad0674beddad7
|
4
|
+
data.tar.gz: 9b459fced3ea79aab42de5e1e2f5cdd434d0a593
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0580af25ab52adb27af93106bed71282011e204ab28ca45f66e3fb0c4d49baeb89a23461e5737db5aa70af95858d4789ec9907a6211719a43e9684d07ff7d382'
|
7
|
+
data.tar.gz: 2cdfbb3239ed2f698851de036326d6ad9ec54a90bb49d0b9ee0b4715d7a7de0def94e82d1adda62103c0d84b9d7324d80d293f1f842639001c3ea84cf21ea50e
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/hypo/component.rb
CHANGED
@@ -2,13 +2,15 @@ module Hypo
|
|
2
2
|
class Component
|
3
3
|
attr_reader :name, :type
|
4
4
|
|
5
|
-
def initialize(type)
|
5
|
+
def initialize(type, container)
|
6
6
|
@type = type
|
7
|
-
@name = type.name.gsub(/(.)([A-Z](?=[a-z]))/,'\1_\2').downcase.to_sym
|
7
|
+
@name = type.name.gsub(/(.)([A-Z](?=[a-z]))/,'\1_\2').delete('::').downcase.to_sym
|
8
|
+
@container = container
|
8
9
|
end
|
9
10
|
|
10
11
|
def instance
|
11
|
-
|
12
|
+
dependencies = @type.instance_method(:initialize).parameters.map{|p| @container.resolve(p[1])}
|
13
|
+
@instance = @type.new(*dependencies) if @instance.nil?
|
12
14
|
|
13
15
|
@instance
|
14
16
|
end
|
data/lib/hypo/container.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'hypo/
|
1
|
+
require 'hypo/container_error'
|
2
2
|
require 'hypo/component'
|
3
3
|
|
4
4
|
module Hypo
|
@@ -8,12 +8,19 @@ module Hypo
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def register(type)
|
11
|
-
component = Component.new(type)
|
11
|
+
component = Component.new(type, self)
|
12
|
+
if @components.key?(component.name)
|
13
|
+
raise ContainerError, "Component of type \"#{component.type.to_s}\" has already been registered"
|
14
|
+
end
|
15
|
+
|
12
16
|
@components[component.name] = component
|
13
17
|
end
|
14
18
|
|
15
19
|
def resolve(name)
|
16
|
-
|
20
|
+
unless @components.key?(name)
|
21
|
+
raise ContainerError, "Component with name \"#{name}\" is not registered"
|
22
|
+
end
|
23
|
+
|
17
24
|
@components[name].instance
|
18
25
|
end
|
19
26
|
end
|
data/lib/hypo/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.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: 2017-08-
|
11
|
+
date: 2017-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,7 +72,7 @@ files:
|
|
72
72
|
- lib/hypo.rb
|
73
73
|
- lib/hypo/component.rb
|
74
74
|
- lib/hypo/container.rb
|
75
|
-
- lib/hypo/
|
75
|
+
- lib/hypo/container_error.rb
|
76
76
|
- lib/hypo/version.rb
|
77
77
|
homepage: https://github.com/cylon-v/hypo
|
78
78
|
licenses:
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.6.
|
98
|
+
rubygems_version: 2.6.13
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: Hypo is sinless general purpose IoC container
|