hypo 0.3.0 → 0.4.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
2
  SHA1:
3
- metadata.gz: c013df3b3209930f2bf4dd5a0c1b59c66b0f52f8
4
- data.tar.gz: 72a5542b3f2993539df0d08cd0f0eee12365c7ad
3
+ metadata.gz: 16e2327263264e9d87d5a3bbbcfb69639f9d8a97
4
+ data.tar.gz: 2c188346ea7e3ebf43420daff2ce41cdbc10bba7
5
5
  SHA512:
6
- metadata.gz: 0141b660aa08e573ea7b397b58fd3ba61b16fd6aaf856f08d2e23bb1c9e8c340b0970ddb65c529882104239229ace596a2dc3ad02c31ed31dca3b4551c3e0bb5
7
- data.tar.gz: 38b2512a45a22eebc92eaddc07aeca23d1e053a88c6b518d35001b578ea668b7d95626bfada76cbd2c98470d0b7be1bb027faf3a13081f4822dbb5fed4ac5d9b
6
+ metadata.gz: 32e602357537e0c5936ea8e3df4b2ec7cae3929e9be97566856ee282b6464c9b6958597e23bf29b4713e8276d94f11edcbbe29c729088875bba43cc30cb4bf8c
7
+ data.tar.gz: 4f66a7f5368809046dcdd4218798c3ad5fad65612c319511f8926d26ec2dfa0b7eee182ff8d8a584efc5a26b62d3440df325a08da3a9b03913438ca036f88000
@@ -1,5 +1,6 @@
1
1
  require 'hypo/container_error'
2
- require 'hypo/component'
2
+ require 'hypo/lazy_component'
3
+ require 'hypo/simple_component'
3
4
 
4
5
  module Hypo
5
6
  class Container
@@ -7,8 +8,10 @@ module Hypo
7
8
  @components = {}
8
9
  end
9
10
 
10
- def register(type, name = nil)
11
- component = Component.new(type, self, name)
11
+ def register(item, name = nil)
12
+ type = item.is_a?(Class) ? LazyComponent : SimpleComponent
13
+ component = type.new(item, self, name)
14
+
12
15
  if @components.key?(component.name)
13
16
  raise ContainerError, "Component of type \"#{component.type.to_s}\" has already been registered"
14
17
  end
@@ -1,5 +1,5 @@
1
1
  module Hypo
2
- class Component
2
+ class LazyComponent
3
3
  attr_reader :name, :type
4
4
 
5
5
  def initialize(type, container, name = nil)
@@ -0,0 +1,17 @@
1
+ module Hypo
2
+ class SimpleComponent
3
+ attr_reader :name
4
+
5
+ def initialize(object, container, name)
6
+ raise ContainerError, 'Registered object should have a name' if name.nil?
7
+
8
+ @object = object
9
+ @name = name
10
+ @container = container
11
+ end
12
+
13
+ def instance
14
+ @object
15
+ end
16
+ end
17
+ end
data/lib/hypo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hypo
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hypo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kalinkin
@@ -70,9 +70,10 @@ files:
70
70
  - bin/setup
71
71
  - hypo.gemspec
72
72
  - lib/hypo.rb
73
- - lib/hypo/component.rb
74
73
  - lib/hypo/container.rb
75
74
  - lib/hypo/container_error.rb
75
+ - lib/hypo/lazy_component.rb
76
+ - lib/hypo/simple_component.rb
76
77
  - lib/hypo/version.rb
77
78
  homepage: https://github.com/cylon-v/hypo
78
79
  licenses: