lazy_injector 0.1.1 → 0.1.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
2
  SHA1:
3
- metadata.gz: 9a0c650df7f867d9be620caf288c06a2fac9a992
4
- data.tar.gz: 9c9ef722e21813c73c8b1b2429e6538210447aed
3
+ metadata.gz: 22b50e3c4abf27aa81ea7d2f7eb3b131decc1fef
4
+ data.tar.gz: 37054d770cd6373c9d1180a4c75af2ff783f9374
5
5
  SHA512:
6
- metadata.gz: 457b2199a3a9474d9abbab931558493970994ed2d8d99ae9ba5e63c9a77f3d4b586889ea3a663ab8d7cfa2eb78c5efc7c252d92519902ed516094ad5c783397f
7
- data.tar.gz: d28a1908cd7284255083848fd91d02ed263764455cb28b53793ccc78e7b270d901e50405637dc906b7346f9d3e2a4452178eb8984cc9139e5ab6af77bddfbf9b
6
+ metadata.gz: 25d022a4b0a868ee15fa8195401f5b3b33230426abddb9c40102efeacd3683b26ea91f0ab30d66aa3d81d538d106d631088b5f71de59d06ffb74a81a58ae7c07
7
+ data.tar.gz: 5bb9688c42bf8ef9d6422632b4802854f2b885405a78145cb6e2c2792db32d7dd4d05d7dbfda33c61cc218ab16f758fbbe447f3884f189fe8aa6d93ff0324291
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/alexei-lexx/lazy-injector.svg?branch=master)](https://travis-ci.org/alexei-lexx/lazy-injector)
2
+
1
3
  # LazyInjector
2
4
 
3
5
  Use Lazy Injector to define dependencies and inject them into your code.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
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
 
6
- task :default => :spec
6
+ task default: :spec
data/examples/basics.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'lazy_injector'
2
2
  require 'ostruct'
3
3
 
4
- module Dependencies
4
+ module Parts
5
5
  include LazyInjector
6
6
 
7
7
  register(:wheel_factory) { Struct.new(:axle, :side) }
@@ -16,6 +16,11 @@ module Dependencies
16
16
  end
17
17
 
18
18
  register(:engine) { OpenStruct.new }
19
+ end
20
+
21
+ module Dependencies
22
+ include LazyInjector
23
+ include Parts
19
24
 
20
25
  register :car do
21
26
  OpenStruct.new(engine: engine, wheels: wheels)
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ['lib']
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.11'
26
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
27
  spec.add_development_dependency 'rspec', '~> 3.0'
28
28
  spec.add_development_dependency 'rubocop'
29
29
  end
data/lib/lazy_injector.rb CHANGED
@@ -6,14 +6,14 @@ module LazyInjector
6
6
  end
7
7
 
8
8
  module ClassMethods
9
- def register(name)
9
+ def register(name, &block)
10
10
  define_method name do
11
11
  @lazy_injector ||= {}
12
12
 
13
13
  if @lazy_injector.key?(name)
14
14
  @lazy_injector[name]
15
15
  else
16
- @lazy_injector[name] = block_given? ? yield : nil
16
+ @lazy_injector[name] = block and instance_eval(&block)
17
17
  end
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module LazyInjector
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_injector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexei L