injected-dependencies 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d252ac7df26381b59da8a06bca2c87b65b95510f410a388d5ffde0b523db7222
4
+ data.tar.gz: d10f954434f808a329d8b60dfd0c0e8019b3de0d0fb7657f58525334d74b0962
5
+ SHA512:
6
+ metadata.gz: ee42727048bad44f817ce1d6e248c0a7bf7df04369f83b3bce1d0759f9768217888080d00be4c4479d9e3b8ddee6a1919916fff0445489f7dfda89ce9b54fa7e
7
+ data.tar.gz: f61d059ba5fd994d32e5dfdd2cda2e0e70269f348b564aabdd5f78c7ae2846ed1f19c1f9ae7002ff9984a0e1a36fe308e32cc5c83a120a5a74cdcbf59f7e84ee
@@ -0,0 +1,13 @@
1
+ *.swp
2
+ /out/
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,10 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Metrics/MethodLength:
5
+ Max: 20
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - '**/*_spec.rb'
10
+ - '**/*.gemspec'
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -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 TODO: Write your email address. 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,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby-injected.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,110 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ injected-dependencies (0.1.0)
5
+ rest-client (>= 1.8.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.1)
11
+ coderay (1.1.3)
12
+ coveralls (0.7.1)
13
+ multi_json (~> 1.3)
14
+ rest-client
15
+ simplecov (>= 0.7)
16
+ term-ansicolor
17
+ thor
18
+ diff-lcs (1.4.4)
19
+ docile (1.3.2)
20
+ domain_name (0.5.20190701)
21
+ unf (>= 0.0.5, < 1.0.0)
22
+ gem-release (2.1.1)
23
+ http-accept (1.7.0)
24
+ http-cookie (1.0.3)
25
+ domain_name (~> 0.5)
26
+ method_source (1.0.0)
27
+ mime-types (3.3.1)
28
+ mime-types-data (~> 3.2015)
29
+ mime-types-data (3.2020.0512)
30
+ multi_json (1.14.1)
31
+ netrc (0.11.0)
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
+ pry-doc (1.1.0)
39
+ pry (~> 0.11)
40
+ yard (~> 0.9.11)
41
+ rainbow (3.0.0)
42
+ rake (12.3.3)
43
+ regexp_parser (1.7.1)
44
+ rest-client (2.1.0)
45
+ http-accept (>= 1.7.0, < 2.0)
46
+ http-cookie (>= 1.0.2, < 2.0)
47
+ mime-types (>= 1.16, < 4.0)
48
+ netrc (~> 0.8)
49
+ rexml (3.2.4)
50
+ rspec (3.9.0)
51
+ rspec-core (~> 3.9.0)
52
+ rspec-expectations (~> 3.9.0)
53
+ rspec-mocks (~> 3.9.0)
54
+ rspec-core (3.9.2)
55
+ rspec-support (~> 3.9.3)
56
+ rspec-expectations (3.9.2)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.9.0)
59
+ rspec-mocks (3.9.1)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.9.0)
62
+ rspec-support (3.9.3)
63
+ rubocop (0.86.0)
64
+ parallel (~> 1.10)
65
+ parser (>= 2.7.0.1)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ regexp_parser (>= 1.7)
68
+ rexml
69
+ rubocop-ast (>= 0.0.3, < 1.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (>= 1.4.0, < 2.0)
72
+ rubocop-ast (0.1.0)
73
+ parser (>= 2.7.0.1)
74
+ ruby-progressbar (1.10.1)
75
+ simplecov (0.18.5)
76
+ docile (~> 1.1)
77
+ simplecov-html (~> 0.11)
78
+ simplecov-cobertura (1.3.1)
79
+ simplecov (~> 0.8)
80
+ simplecov-html (0.12.2)
81
+ sync (0.5.0)
82
+ term-ansicolor (1.7.1)
83
+ tins (~> 1.0)
84
+ thor (1.0.1)
85
+ tins (1.25.0)
86
+ sync
87
+ unf (0.1.4)
88
+ unf_ext
89
+ unf_ext (0.0.7.7)
90
+ unicode-display_width (1.7.0)
91
+ yard (0.9.25)
92
+
93
+ PLATFORMS
94
+ ruby
95
+
96
+ DEPENDENCIES
97
+ bundler
98
+ coveralls
99
+ gem-release
100
+ injected-dependencies!
101
+ pry
102
+ pry-doc
103
+ rake (~> 12.0)
104
+ rspec (~> 3.0)
105
+ rubocop
106
+ simplecov
107
+ simplecov-cobertura
108
+
109
+ BUNDLED WITH
110
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 TODO: Write your name
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,79 @@
1
+ # Injected
2
+
3
+ Simple Guice-inspird dependency injection framework for Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'injected'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install injected
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'injected'
25
+
26
+ class DemoInterface < Injected::Interface
27
+ interface_method(:demo, :arg1, :arg2, arg3: :default)
28
+ end
29
+
30
+ class DemoImplementation < Injected::Implementation
31
+ implements DemoInterface
32
+
33
+ def demo(arg1, arg2, arg3: :wat)
34
+ "arg1: #{arg1}; arg2: #{arg2}; arg3: #{arg3}"
35
+ end
36
+ end
37
+
38
+ class DemoService < Injected::Instance
39
+ injected(DemoInterface, :demo_dependency)
40
+
41
+ def demo
42
+ demo_dependency.demo(1, 2)
43
+ end
44
+ end
45
+
46
+ injector = Injected::Injector.new(
47
+ DemoInterface => DemoImplementation
48
+ )
49
+
50
+ demo_service = injector.instance(DemoService)
51
+ demo_service.demo #=> "arg1: 1; arg2: 2; arg3: default"
52
+
53
+ # inside demo_service
54
+
55
+ demo_interface.demo(1, 'two')
56
+ # => "arg1: 1; arg2: two; arg3: default"
57
+
58
+ demo_interface.demo(1, 'two', arg3: :three)
59
+ # => "arg1: 1; arg2: two; arg3: three"
60
+ ```
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ 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).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/watmin/injected. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/watmin/injected/blob/master/CODE_OF_CONDUCT.md).
71
+
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
76
+
77
+ ## Code of Conduct
78
+
79
+ Everyone interacting in the Ruby::Injected project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/watmin/injected/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+ # require 'yard'
7
+ # require 'yard/rake/yardoc_task'
8
+ # require 'yardstick/rake/measurement'
9
+ # require 'yardstick/rake/verify'
10
+
11
+ def empty_directory(directory)
12
+ return unless File.exist?(directory)
13
+
14
+ FileUtils.remove_entry(directory)
15
+ FileUtils.mkdir(directory)
16
+ end
17
+
18
+ # clean up the workspace
19
+ task(:clean) do
20
+ empty_directory('doc')
21
+ empty_directory('out')
22
+ empty_directory('pkg')
23
+ end
24
+
25
+ # console
26
+ task(:console) do
27
+ sh 'bundle exec bin/console'
28
+ end
29
+
30
+ # unit tests
31
+ RSpec::Core::RakeTask.new(:spec) do |task|
32
+ task.pattern = 'spec/**/*_spec.rb'
33
+ task.rspec_opts = '--require spec_helper ' \
34
+ '--format documentation ' \
35
+ '--format html ' \
36
+ '--out out/rspec_unit.html'
37
+ end
38
+ task(default: :spec)
39
+
40
+ # configure rubocop
41
+ RuboCop::RakeTask.new(:rubocop) do |task|
42
+ task.options = [
43
+ '--format', 'simple',
44
+ '--format', 'html',
45
+ '--out', 'out/rubocop.html',
46
+ 'lib/**/*.rb',
47
+ 'spec/**/*.rb'
48
+ ]
49
+ end
50
+ task(default: :rubocop)
51
+
52
+ # # configure yard
53
+ # YARD::Rake::YardocTask.new(:yard) do |task|
54
+ # task.files = Dir['lib/**/*.rb']
55
+ # task.options = [
56
+ # '--quiet' # YARD doesn't like the methods that received (**args)
57
+ # ]
58
+ # task.stats_options = [
59
+ # '--list-undoc'
60
+ # ]
61
+ # end
62
+ # task(default: :yard)
63
+ #
64
+ # # documentation coverage
65
+ # Yardstick::Rake::Measurement.new(:yardstick_measure) do |task|
66
+ # task.output = 'out/yard-report.txt'
67
+ # end
68
+ # task(default: :yardstick_measure)
69
+ #
70
+ # # documentation enforcement
71
+ # Yardstick::Rake::Verify.new(:yardstick_verify) do |task|
72
+ # task.threshold = 100
73
+ # end
74
+ # task(default: :yardstick_verify)
75
+ #
76
+ # # Require tests, syntax and documentation to pass before building
77
+ # task(build: %i[spec rubocop yard yardstick_measure yardstick_verify])
78
+ task(build: %i[spec rubocop])
79
+
80
+ # Require a succesful build before release
81
+ task(release: %i[build])
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'injected/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'injected-dependencies'
9
+ spec.version = Injected::VERSION
10
+ spec.authors = 'John Shields'
11
+ spec.email = 'john@shields.wtf'
12
+
13
+ spec.summary = 'Guice inspired dependency injection'
14
+ spec.homepage = 'https://github.com/watmin/Ruby-injected-dependencies'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
17
+
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler'
30
+ spec.add_development_dependency 'coveralls'
31
+ spec.add_development_dependency 'gem-release'
32
+ spec.add_development_dependency 'pry'
33
+ spec.add_development_dependency 'pry-doc'
34
+ spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec'
36
+ spec.add_development_dependency 'rubocop'
37
+ spec.add_development_dependency 'simplecov'
38
+ spec.add_development_dependency 'simplecov-cobertura'
39
+ # spec.add_development_dependency 'yard'
40
+ # spec.add_development_dependency 'yardstick'
41
+
42
+ spec.add_dependency 'rest-client', '>= 1.8.0'
43
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'pry'
7
+
8
+ require 'injected'
9
+
10
+ class DemoInterface < Injected::Interface
11
+ interface_method(:demo, :arg1, :arg2, arg3: :default)
12
+ end
13
+
14
+ class DemoImplementation < Injected::Implementation
15
+ implements DemoInterface
16
+
17
+ def demo(arg1, arg2, arg3: :wat)
18
+ "arg1: #{arg1}; arg2: #{arg2}; arg3: #{arg3}"
19
+ end
20
+ end
21
+
22
+ class DemoService < Injected::Instance
23
+ injected(DemoInterface, :demo_dependency)
24
+
25
+ def demo
26
+ demo_dependency.demo(1, 2)
27
+ end
28
+ end
29
+
30
+ injector = Injected::Injector.new(
31
+ DemoInterface => DemoImplementation
32
+ )
33
+
34
+ demo_service = injector.instance(DemoService)
35
+
36
+ binding.pry # rubocop:disable Lint/Debugger
37
+
38
+ # demo_service.demo # => "arg1: 1; arg2: 2; arg3: wat"
39
+ # demo_service.pry
40
+ # demo_dependency.demo(1, 'two')
41
+ # demo_dependency.demo(1, 'two', arg3: :three)
@@ -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
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'injected/all'
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'injected/version'
4
+
5
+ require 'injected/interface_dsl'
6
+ require 'injected/interface'
7
+
8
+ require 'injected/implementation_dsl'
9
+ require 'injected/implementation'
10
+
11
+ require 'injected/instance_dsl'
12
+ require 'injected/instance'
13
+
14
+ require 'injected/injector'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Injected
4
+ class Implementation
5
+ extend Injected::ImplementationDsl
6
+ end
7
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Injected
4
+ module ImplementationDsl
5
+ def implements(interface)
6
+ @implemented_interface = interface
7
+ end
8
+
9
+ private
10
+
11
+ attr_reader :implemented_interface
12
+
13
+ def method_added(method_name)
14
+ super
15
+
16
+ return unless invalid_arity?(method_name)
17
+
18
+ raise ArgumentError, "Invalid arity for implemented method #{method_name} for #{self}. " \
19
+ "Expected #{interface_method(method_name).parameters}, " \
20
+ "got #{instance_method(method_name).parameters}"
21
+ end
22
+
23
+ def interface_method(method_name)
24
+ implemented_interface.interface_methods[method_name]
25
+ end
26
+
27
+ def invalid_arity?(method_name)
28
+ if interface_method(method_name)
29
+ fixed = instance_method(method_name).parameters.map do |type, arg|
30
+ [type == :keyreq ? :key : type, arg]
31
+ end
32
+ interface_method(method_name).parameters != fixed
33
+ else
34
+ false
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Injected
4
+ class Injector
5
+ def initialize(injections)
6
+ @injections = injections
7
+ end
8
+
9
+ def instance(class_name)
10
+ class_name.new(@injections)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Injected
4
+ class Instance
5
+ extend Injected::InstanceDsl
6
+
7
+ def initialize(injections) # rubocop:disable Metrics/AbcSize
8
+ self.class.injected_interfaces&.each do |interface, attribute|
9
+ interface.interface_methods.keys.each do |interface_method|
10
+ raise ArgumentError, "#{self.class} unment dependency #{interface}" unless injections.key?(interface)
11
+ next if injections[interface].instance_methods.include?(interface_method)
12
+
13
+ raise ArgumentError, "Implementation #{injections[interface]} does not implement #{interface_method}"
14
+ end
15
+ instance_variable_set("@#{attribute}", injections[interface].new)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Injected
4
+ module InstanceDsl
5
+ def self.extended(receiver)
6
+ class << receiver
7
+ attr_accessor :injected_interfaces
8
+ end
9
+ end
10
+
11
+ def injected(interface, attribute)
12
+ @injected_interfaces ||= {}
13
+ injected_interfaces[interface] = attribute
14
+ attr_reader attribute
15
+ private attribute
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Injected
4
+ class Interface
5
+ extend Injected::InterfaceDsl
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Injected
4
+ module InterfaceDsl
5
+ def self.extended(receiver)
6
+ class << receiver
7
+ attr_accessor :interface_methods
8
+ end
9
+ end
10
+
11
+ def interface_method(method_name, *args, **optional, &block)
12
+ @interface_methods ||= {}
13
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
14
+ def #{method_name}(#{signature(args, optional, block)}); end
15
+ RUBY_EVAL
16
+ interface_methods[method_name] = instance_method(method_name)
17
+ end
18
+
19
+ def signature(args, optional, block)
20
+ base = [args, optional.map { |k, v| "#{k}: #{v.inspect}" }.join(' ')].flatten(1).reject(&:empty?).join(', ')
21
+ return base unless block
22
+
23
+ [base, '&block'].reject(&:empty?).join(', ')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Injected
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,220 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: injected-dependencies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Shields
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-02 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gem-release
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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
+ - !ruby/object:Gem::Dependency
70
+ name: pry-doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov-cobertura
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rest-client
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 1.8.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 1.8.0
167
+ description:
168
+ email: john@shields.wtf
169
+ executables: []
170
+ extensions: []
171
+ extra_rdoc_files: []
172
+ files:
173
+ - ".gitignore"
174
+ - ".rspec"
175
+ - ".rubocop.yml"
176
+ - ".travis.yml"
177
+ - CODE_OF_CONDUCT.md
178
+ - Gemfile
179
+ - Gemfile.lock
180
+ - LICENSE.txt
181
+ - README.md
182
+ - Rakefile
183
+ - Ruby-injected-dependencies.gemspec
184
+ - bin/console
185
+ - bin/setup
186
+ - lib/injected.rb
187
+ - lib/injected/all.rb
188
+ - lib/injected/implementation.rb
189
+ - lib/injected/implementation_dsl.rb
190
+ - lib/injected/injector.rb
191
+ - lib/injected/instance.rb
192
+ - lib/injected/instance_dsl.rb
193
+ - lib/injected/interface.rb
194
+ - lib/injected/interface_dsl.rb
195
+ - lib/injected/version.rb
196
+ homepage: https://github.com/watmin/Ruby-injected-dependencies
197
+ licenses:
198
+ - MIT
199
+ metadata:
200
+ allowed_push_host: https://rubygems.org
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: 2.3.0
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ requirements: []
216
+ rubygems_version: 3.1.2
217
+ signing_key:
218
+ specification_version: 4
219
+ summary: Guice inspired dependency injection
220
+ test_files: []