lazy_injector 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +6 -0
- data/examples/basics.rb +27 -0
- data/lazy_injector.gemspec +29 -0
- data/lib/lazy_injector/version.rb +3 -0
- data/lib/lazy_injector.rb +21 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e56a8636443f82987ed75a10255ad7cb2a8e1e4e
|
4
|
+
data.tar.gz: bc16cf31cdc1ac692b905f6cfe7ff6cdb91f6d6e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4341a002d12c4a7470c86969e2aca28fe75c927a5578e86834ca1dd120cf78bbe0010067234e8626b3d5aadc4626d04fc9d2f319730f83239aef2cd834d1747f
|
7
|
+
data.tar.gz: 0006f8abc8e8b5cc71bb3639d306fb3b92e2632e4ff3d968d04b40a14296fcb310d6a62aa11dd7fcae3701644a236e79f9c806cec48e4f71be4dd3fc0a80fe64
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Alexei L
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# LazyInjector
|
2
|
+
|
3
|
+
Use Lazy Injector to define dependencies and inject them into your code.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'lazy_injector'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install lazy_injector
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'lazy_injector'
|
25
|
+
require 'ostruct'
|
26
|
+
|
27
|
+
module Dependencies
|
28
|
+
include LazyInjector
|
29
|
+
|
30
|
+
register(:wheel_factory) { Struct.new(:axle, :side) }
|
31
|
+
|
32
|
+
register :wheels do
|
33
|
+
[
|
34
|
+
wheel_factory.new('front', 'left'),
|
35
|
+
wheel_factory.new('front', 'right'),
|
36
|
+
wheel_factory.new('rear', 'left'),
|
37
|
+
wheel_factory.new('rear', 'right')
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
register(:engine) { OpenStruct.new }
|
42
|
+
|
43
|
+
register :car do
|
44
|
+
OpenStruct.new(engine: engine, wheels: wheels)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
include Dependencies
|
49
|
+
|
50
|
+
p car
|
51
|
+
```
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lazy_injector.
|
60
|
+
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/examples/basics.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'lazy_injector'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Dependencies
|
5
|
+
include LazyInjector
|
6
|
+
|
7
|
+
register(:wheel_factory) { Struct.new(:axle, :side) }
|
8
|
+
|
9
|
+
register :wheels do
|
10
|
+
[
|
11
|
+
wheel_factory.new('front', 'left'),
|
12
|
+
wheel_factory.new('front', 'right'),
|
13
|
+
wheel_factory.new('rear', 'left'),
|
14
|
+
wheel_factory.new('rear', 'right')
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
register(:engine) { OpenStruct.new }
|
19
|
+
|
20
|
+
register :car do
|
21
|
+
OpenStruct.new(engine: engine, wheels: wheels)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
include Dependencies
|
26
|
+
|
27
|
+
p car
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lazy_injector/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'lazy_injector'
|
8
|
+
spec.version = LazyInjector::VERSION
|
9
|
+
spec.authors = ['Alexei L']
|
10
|
+
spec.email = ['alexei.lexx@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Very simple library to inject dependencies'
|
13
|
+
spec.description = 'Very simple library to inject dependencies'
|
14
|
+
spec.homepage = 'https://github.com/alexei-lexx/lazy-injector'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
.reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'rubocop'
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'lazy_injector/version'
|
2
|
+
|
3
|
+
module LazyInjector
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def register(name)
|
10
|
+
define_method name do
|
11
|
+
@lazy_injector ||= {}
|
12
|
+
|
13
|
+
if @lazy_injector.key?(name)
|
14
|
+
@lazy_injector[name]
|
15
|
+
else
|
16
|
+
@lazy_injector[name] = block_given? ? yield : nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lazy_injector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexei L
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Very simple library to inject dependencies
|
70
|
+
email:
|
71
|
+
- alexei.lexx@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- examples/basics.rb
|
85
|
+
- lazy_injector.gemspec
|
86
|
+
- lib/lazy_injector.rb
|
87
|
+
- lib/lazy_injector/version.rb
|
88
|
+
homepage: https://github.com/alexei-lexx/lazy-injector
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.4.8
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Very simple library to inject dependencies
|
112
|
+
test_files: []
|