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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 564fd9d6d97b865381afe67d4eb4fb0ec9fdd2cc
4
- data.tar.gz: d68c4d42b672e9b2b9893b3cbf32d33e60d40bda
3
+ metadata.gz: 39500b4a91ded208c5e5e3dd500ad0674beddad7
4
+ data.tar.gz: 9b459fced3ea79aab42de5e1e2f5cdd434d0a593
5
5
  SHA512:
6
- metadata.gz: 794093523bd47a7d398342bfa16da04e473d645ed8067a49246209ef0e5ab375c5a8a62b91f540f8c33121eadf6de1b8b7503b9020aae25aaeb966da665a44b1
7
- data.tar.gz: b30c083d333c440a24b89573610101a9e695c545663efe302ea9f94d27e2994998a4c7d68dedd64c60f695572f1d0aedb432a3d4174224c19e246ae0bea5ff00
6
+ metadata.gz: '0580af25ab52adb27af93106bed71282011e204ab28ca45f66e3fb0c4d49baeb89a23461e5737db5aa70af95858d4789ec9907a6211719a43e9684d07ff7d382'
7
+ data.tar.gz: 2cdfbb3239ed2f698851de036326d6ad9ec54a90bb49d0b9ee0b4715d7a7de0def94e82d1adda62103c0d84b9d7324d80d293f1f842639001c3ea84cf21ea50e
data/.gitignore CHANGED
@@ -11,3 +11,7 @@
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
13
  .idea
14
+ .gem
15
+ .ruby-version
16
+ .ruby-gemset
17
+ coverage
data/.travis.yml CHANGED
@@ -3,3 +3,4 @@ language: ruby
3
3
  rvm:
4
4
  - 2.4.1
5
5
  before_install: gem install bundler -v 1.15.4
6
+
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'rspec'
8
+ gem 'simplecov', :require => false
8
9
  end
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # Hypo
2
- Hypo is sinless general purpose IoC container.
1
+ # Hypo ![Build Status](https://travis-ci.org/cylon-v/hypo.svg)
2
+ Hypo is sinless general purpose IoC container for Ruby applications.
3
3
 
4
4
  ## Installation
5
5
 
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
@@ -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
- @instance = type.new if @instance.nil?
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
@@ -1,4 +1,4 @@
1
- require 'hypo/resolving_error'
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
- raise ResolvingError, name unless @components.key?(name)
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
@@ -0,0 +1,7 @@
1
+ module Hypo
2
+ class ContainerError < StandardError
3
+ def initialize(message)
4
+ super(message)
5
+ end
6
+ end
7
+ end
data/lib/hypo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hypo
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.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.1.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-30 00:00:00.000000000 Z
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/resolving_error.rb
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.12
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
@@ -1,5 +0,0 @@
1
- class ResolvingError < StandardError
2
- def initialize(name)
3
- super("Component #{name} is not registered")
4
- end
5
- end