smart_injection 0.0.0.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8648636507a04e403ca6e55d0371d3191d248e09e63f9c977128847fc382b00f
4
+ data.tar.gz: 218f815047bf27cd213743ee0db5c82f7676beff59ccc95f0de5dad656a0e028
5
+ SHA512:
6
+ metadata.gz: 8343d93be3d7fe20c1996255a8927d520e8a23a2f024d1af73b40346ddc59add22d4b09aa3b33a8afc744ce60638a68ea98c6beb249f5fdbec254243626b561e
7
+ data.tar.gz: 256144d63e96bf91f2a2b60fd966935a4012c41cf509aa03159dac102c4eb9bc688fb207ec92f99928cb2e695ed5305a9e1601f7f3b0bfb1c386302baa319656
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .rspec_status
10
+ /.idea
11
+ .ruby-version
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,19 @@
1
+ inherit_gem:
2
+ armitage-rubocop:
3
+ - lib/rubocop.general.yml
4
+ - lib/rubocop.rake.yml
5
+ - lib/rubocop.rspec.yml
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 2.7.1
9
+ Include:
10
+ - lib/**/*.rb
11
+ - spec/**/*.rb
12
+ - Gemfile
13
+ - Rakefile
14
+ - smart_injection.gemspec
15
+ - bin/console
16
+
17
+ # NOTE: It is not suitable for infrastracture-level frameworks
18
+ Metrics/ParameterLists:
19
+ Enabled: false
@@ -0,0 +1,23 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ os: linux
5
+ dist: xenial
6
+ jobs:
7
+ fast_finish: true
8
+ include:
9
+ - rvm: 2.4.10
10
+ - rvm: 2.5.8
11
+ - rvm: 2.6.6
12
+ - rvm: 2.7.1
13
+ - rvm: jruby-head
14
+ - rvm: ruby-head
15
+ - rvm: truffleruby
16
+ allow_failures:
17
+ - rvm: ruby-head
18
+ - rvm: jruby-head
19
+ - rvm: truffleruby
20
+ before_install: gem install bundler
21
+ script:
22
+ - bundle exec rake rubocop
23
+ - bundle exec rake rspec
@@ -0,0 +1,2 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at iamdaiver@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,104 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ smart_injection (0.0.0.alpha)
5
+ smart_container (~> 0.7)
6
+ smart_engine (~> 0.7)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.0.3.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.2, >= 2.2.2)
17
+ armitage-rubocop (0.85.1)
18
+ rubocop (= 0.85.1)
19
+ rubocop-performance (= 1.6.1)
20
+ rubocop-rails (= 2.6.0)
21
+ rubocop-rake (= 0.5.1)
22
+ rubocop-rspec (= 1.40.0)
23
+ ast (2.4.1)
24
+ coderay (1.1.3)
25
+ concurrent-ruby (1.1.6)
26
+ diff-lcs (1.4.4)
27
+ docile (1.3.2)
28
+ i18n (1.8.3)
29
+ concurrent-ruby (~> 1.0)
30
+ method_source (1.0.0)
31
+ minitest (5.14.1)
32
+ parallel (1.19.2)
33
+ parser (2.7.1.4)
34
+ ast (~> 2.4.1)
35
+ pry (0.13.1)
36
+ coderay (~> 1.1)
37
+ method_source (~> 1.0)
38
+ rack (2.2.3)
39
+ rainbow (3.0.0)
40
+ rake (13.0.1)
41
+ regexp_parser (1.7.1)
42
+ rexml (3.2.4)
43
+ rspec (3.9.0)
44
+ rspec-core (~> 3.9.0)
45
+ rspec-expectations (~> 3.9.0)
46
+ rspec-mocks (~> 3.9.0)
47
+ rspec-core (3.9.2)
48
+ rspec-support (~> 3.9.3)
49
+ rspec-expectations (3.9.2)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.9.0)
52
+ rspec-mocks (3.9.1)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.9.0)
55
+ rspec-support (3.9.3)
56
+ rubocop (0.85.1)
57
+ parallel (~> 1.10)
58
+ parser (>= 2.7.0.1)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ regexp_parser (>= 1.7)
61
+ rexml
62
+ rubocop-ast (>= 0.0.3)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (>= 1.4.0, < 2.0)
65
+ rubocop-ast (0.1.0)
66
+ parser (>= 2.7.0.1)
67
+ rubocop-performance (1.6.1)
68
+ rubocop (>= 0.71.0)
69
+ rubocop-rails (2.6.0)
70
+ activesupport (>= 4.2.0)
71
+ rack (>= 1.1)
72
+ rubocop (>= 0.82.0)
73
+ rubocop-rake (0.5.1)
74
+ rubocop
75
+ rubocop-rspec (1.40.0)
76
+ rubocop (>= 0.68.1)
77
+ ruby-progressbar (1.10.1)
78
+ simplecov (0.18.5)
79
+ docile (~> 1.1)
80
+ simplecov-html (~> 0.11)
81
+ simplecov-html (0.12.2)
82
+ smart_container (0.7.0)
83
+ smart_engine (~> 0.5)
84
+ smart_engine (0.7.0)
85
+ thread_safe (0.3.6)
86
+ tzinfo (1.2.7)
87
+ thread_safe (~> 0.1)
88
+ unicode-display_width (1.7.0)
89
+ zeitwerk (2.3.1)
90
+
91
+ PLATFORMS
92
+ ruby
93
+
94
+ DEPENDENCIES
95
+ armitage-rubocop (~> 0.85)
96
+ bundler (~> 2.1)
97
+ pry (~> 0.13)
98
+ rake (~> 13.0)
99
+ rspec (~> 3.9)
100
+ simplecov (~> 0.18)
101
+ smart_injection!
102
+
103
+ BUNDLED WITH
104
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Rustam Ibragimov
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.
@@ -0,0 +1,122 @@
1
+ # SmartCore::Injection &middot; [![Gem Version](https://badge.fury.io/rb/smart_injection.svg)](https://badge.fury.io/rb/smart_injection) [![Build Status](https://travis-ci.org/smart-rb/smart_injection.svg?branch=master)](https://travis-ci.org/smart-rb/smart_injection)
2
+
3
+ Dependency injection principles and idioms realized in scope of Ruby.
4
+
5
+ ---
6
+
7
+ ## Major Features
8
+
9
+ - `method-injection` strategy
10
+ - `soon:` constructor injection strategy;
11
+ - `soon:` attribute injection strategy;
12
+ - realized as a mixin;
13
+ - instance-method dependency injection;
14
+ - class-method dependency injection;
15
+ - multiple IoC-container registration;
16
+ - static and dynamic bindings;
17
+ - support for memoization with run-time dependency-switchable re-memoization;
18
+ - an ability to import dependencies from the list of IoC-containers
19
+ - an ability to import from the pre-configured default IoC-container(s);
20
+ - an ability to import from any manually passed IoC-container;
21
+ - privacy control of injected dependency (public/private/protected);
22
+
23
+ ---
24
+
25
+ ## Installation
26
+
27
+ ```ruby
28
+ gem 'smart_injection'
29
+ ```
30
+
31
+ ```shell
32
+ bundle install
33
+ # --- or ---
34
+ gem install smart_injection
35
+ ```
36
+
37
+ ```ruby
38
+ require 'smart_core/injection'
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Synopsis
44
+
45
+ Create some containers:
46
+
47
+ ```ruby
48
+ AppContainer = SmartCore::Container.define do
49
+ namespace(:data_storage) do
50
+ register(:main) { Sequel::Model.db }
51
+ register(:cache) { Redis.new }
52
+ end
53
+ end
54
+
55
+ ServiceContainer = SmartCore::Container.define do
56
+ namespace(:rands) do
57
+ register(:alphanum) { -> { SeureRandom.alphanumeric } }
58
+ register(:hex) { -> { SecureRandom.hex } }
59
+ end
60
+ end
61
+
62
+ GlobalContainer = SmartCore::Container.define do
63
+ namespace(:phone_clients) do
64
+ register(:nexmo) { Nexmo.new }
65
+ register(:twilio) { Twilio.new }
66
+ end
67
+ end
68
+ ```
69
+
70
+ And work with dependency injection:
71
+
72
+ ```ruby
73
+ class MiniService
74
+ include SmartCore::Injection
75
+
76
+ register_container(AppContainer)
77
+ register_container(ServiceContainer)
78
+
79
+ # --- or ---
80
+ include SmartCore::Injection(AppContainer, ServiceContainer)
81
+
82
+ # --- or ---
83
+ include SmartCore::Container
84
+ register_container(AppContainer, ServiceContainer)
85
+
86
+ # import dependencies to an instance
87
+ import { db: 'data_storage.main' }, bind: :dynamic, access: :private
88
+ import { rnd: 'rands.alphanum' }, bind: :static, memoize: true
89
+
90
+ # import dependencies to a class
91
+ import_static { cache: 'data_storage.cache', hexer: 'rands.hex' }, bind: :static
92
+
93
+ # import from a non-registered container
94
+ import { phone_client: 'phone_clients.nexmo' }, from: GlobalContainer
95
+
96
+ def call
97
+ db # => returns data_storage.main
98
+ rnd # => returns rands.alphanum
99
+ self.class.cache # => returns data_storage.cache
100
+ self.class.hexer # => returns rands.hexer
101
+ phone_client # => returns phone_clients.nexmo
102
+ end
103
+ end
104
+ ```
105
+
106
+ ---
107
+
108
+ ## Contributing
109
+
110
+ - Fork it ( https://github.com/smart-rb/smart_injection )
111
+ - Create your feature branch (`git checkout -b feature/my-new-feature`)
112
+ - Commit your changes (`git commit -am '[feature_context] Add some feature'`)
113
+ - Push to the branch (`git push origin feature/my-new-feature`)
114
+ - Create new Pull Request
115
+
116
+ ## License
117
+
118
+ Released under MIT License.
119
+
120
+ ## Authors
121
+
122
+ [Rustam Ibragimov](https://github.com/0exp)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop'
6
+ require 'rubocop/rake_task'
7
+ require 'rubocop-performance'
8
+ require 'rubocop-rspec'
9
+ require 'rubocop-rake'
10
+
11
+ RuboCop::RakeTask.new(:rubocop) do |t|
12
+ config_path = File.expand_path(File.join('.rubocop.yml'), __dir__)
13
+ t.options = ['--config', config_path]
14
+ t.requires << 'rubocop-rspec'
15
+ t.requires << 'rubocop-performance'
16
+ t.requires << 'rubocop-rake'
17
+ end
18
+
19
+ RSpec::Core::RakeTask.new(:rspec)
20
+
21
+ task default: :rspec
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'smart_core/injection'
6
+
7
+ require 'irb'
8
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here