receptacle 0.3.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/receptacle.rb CHANGED
@@ -1,13 +1,7 @@
1
1
  # frozen_string_literal: true
2
- require 'receptacle/version'
3
- require 'receptacle/interface_methods'
4
- require 'receptacle/method_delegation'
2
+
3
+ require "receptacle/version"
4
+ require "receptacle/repo"
5
5
 
6
6
  module Receptacle
7
- module Repo
8
- def self.included(base)
9
- base.extend(InterfaceMethods)
10
- base.extend(MethodDelegation)
11
- end
12
- end
13
7
  end
data/receptacle.gemspec CHANGED
@@ -1,38 +1,43 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
- lib = File.expand_path('../lib', __FILE__)
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'receptacle/version'
5
+ require "receptacle/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'receptacle'
9
- spec.version = Receptacle::VERSION
10
- spec.authors = ['Andreas Eger']
11
- spec.email = ['dev@eger-andreas.de']
8
+ spec.name = "receptacle"
9
+ spec.version = Receptacle::VERSION
10
+ spec.authors = ["Andreas Eger"]
11
+ spec.email = ["dev@eger-andreas.de"]
12
12
 
13
- spec.summary = 'repository pattern'
14
- spec.description = 'provides functionality for the repository or strategy pattern'
15
- spec.homepage = 'https://github.com/andreaseger/receptacle'
16
- spec.license = 'MIT'
13
+ spec.summary = "repository pattern"
14
+ spec.description = "provides functionality for the repository or strategy pattern"
15
+ spec.homepage = "https://github.com/andreaseger/receptacle"
16
+ spec.license = "MIT"
17
17
 
18
- spec.required_ruby_version = '~> 2.1'
18
+ spec.required_ruby_version = if RUBY_ENGINE == "jruby"
19
+ ">= 2.6"
20
+ else
21
+ ">= 2.7"
22
+ end
19
23
 
20
24
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
25
  f.match(%r{^(test|spec|features)/})
22
26
  end
23
- spec.bindir = 'exe'
24
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ['lib']
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", ">= 1.13", "< 3"
32
+ spec.add_development_dependency "pry"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.11"
35
+ spec.add_development_dependency "rspec_junit_formatter"
36
+ spec.add_development_dependency "rt_rubocop_defaults", "~> 2.4"
37
+ spec.add_development_dependency "rubocop", "~> 1.37"
38
+ spec.add_development_dependency "rubocop-rspec", "~> 2.14"
39
+ spec.add_development_dependency "rubocop_runner", "~> 2.2"
40
+ spec.add_development_dependency "simplecov", "~> 0.13"
26
41
 
27
- spec.add_development_dependency 'bundler', '~> 1.13'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'minitest', '~> 5.0'
30
- spec.add_development_dependency 'pry'
31
- spec.add_development_dependency 'rubocop_runner', '~> 2.0'
32
- spec.add_development_dependency 'rubocop', '~> 0.46.0'
33
- spec.add_development_dependency 'simplecov', '~> 0.13'
34
- spec.add_development_dependency 'codecov'
35
- spec.add_development_dependency 'guard'
36
- spec.add_development_dependency 'guard-minitest'
37
- spec.add_development_dependency 'guard-rubocop'
42
+ spec.metadata["rubygems_mfa_required"] = "true"
38
43
  end
data/upgrade_notes.md ADDED
@@ -0,0 +1,45 @@
1
+ # Upgrade notes
2
+
3
+ ## Upgrade from 1.0.0 to 2.0.0
4
+ The test helper `ensure_method_delegators` has been removed. If you used it, just remove its usage.
5
+
6
+ If you do not use wrappers, there is nothing further you need to do to upgrade.
7
+
8
+ The wrapper interface changed. With version 1.0 you had to implement methods prefixed with `before_` and `after_`. The return value of before-hooks where used as arguments to the next wrapper, while the return value of after-hooks was passed down to the previous wrapper. E.g:
9
+
10
+ ```ruby
11
+ module Wrapper
12
+ class Validator
13
+ def before_find(id:)
14
+ raise ArgumentError if id.nil?
15
+ {id: id}
16
+ end
17
+ end
18
+
19
+ class ModelMapper
20
+ def after_find(return_value, **_kwargs)
21
+ Model::User.new(return_value)
22
+ end
23
+ end
24
+ end
25
+ ```
26
+
27
+ In version 2.0 there are no before- and after-methods anymore. Instead you provide one method that wraps around the next wrapper or the strategy. You need to name the wrapper methods exactly as they are named in your strategy and you call `yield` to call the next wrapper. E.g:
28
+
29
+ ```ruby
30
+ module Wrapper
31
+ class Validator
32
+ def find(id:)
33
+ raise ArgumentError if id.nil?
34
+ yield(id: id)
35
+ end
36
+ end
37
+
38
+ class ModelMapper
39
+ def find(id:)
40
+ return_value = yield(id: id)
41
+ Model::User.new(return_value)
42
+ end
43
+ end
44
+ end
45
+ ```
metadata CHANGED
@@ -1,29 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: receptacle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Eger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-14 00:00:00.000000000 Z
11
+ date: 2023-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.13'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.13'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: pry
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: rake
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -39,21 +59,21 @@ dependencies:
39
59
  - !ruby/object:Gem::Version
40
60
  version: '10.0'
41
61
  - !ruby/object:Gem::Dependency
42
- name: minitest
62
+ name: rspec
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '5.0'
67
+ version: '3.11'
48
68
  type: :development
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '5.0'
74
+ version: '3.11'
55
75
  - !ruby/object:Gem::Dependency
56
- name: pry
76
+ name: rspec_junit_formatter
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
79
  - - ">="
@@ -67,103 +87,75 @@ dependencies:
67
87
  - !ruby/object:Gem::Version
68
88
  version: '0'
69
89
  - !ruby/object:Gem::Dependency
70
- name: rubocop_runner
90
+ name: rt_rubocop_defaults
71
91
  requirement: !ruby/object:Gem::Requirement
72
92
  requirements:
73
93
  - - "~>"
74
94
  - !ruby/object:Gem::Version
75
- version: '2.0'
95
+ version: '2.4'
76
96
  type: :development
77
97
  prerelease: false
78
98
  version_requirements: !ruby/object:Gem::Requirement
79
99
  requirements:
80
100
  - - "~>"
81
101
  - !ruby/object:Gem::Version
82
- version: '2.0'
102
+ version: '2.4'
83
103
  - !ruby/object:Gem::Dependency
84
104
  name: rubocop
85
105
  requirement: !ruby/object:Gem::Requirement
86
106
  requirements:
87
107
  - - "~>"
88
108
  - !ruby/object:Gem::Version
89
- version: 0.46.0
109
+ version: '1.37'
90
110
  type: :development
91
111
  prerelease: false
92
112
  version_requirements: !ruby/object:Gem::Requirement
93
113
  requirements:
94
114
  - - "~>"
95
115
  - !ruby/object:Gem::Version
96
- version: 0.46.0
116
+ version: '1.37'
97
117
  - !ruby/object:Gem::Dependency
98
- name: simplecov
118
+ name: rubocop-rspec
99
119
  requirement: !ruby/object:Gem::Requirement
100
120
  requirements:
101
121
  - - "~>"
102
122
  - !ruby/object:Gem::Version
103
- version: '0.13'
123
+ version: '2.14'
104
124
  type: :development
105
125
  prerelease: false
106
126
  version_requirements: !ruby/object:Gem::Requirement
107
127
  requirements:
108
128
  - - "~>"
109
129
  - !ruby/object:Gem::Version
110
- version: '0.13'
111
- - !ruby/object:Gem::Dependency
112
- name: codecov
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: guard
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'
130
+ version: '2.14'
139
131
  - !ruby/object:Gem::Dependency
140
- name: guard-minitest
132
+ name: rubocop_runner
141
133
  requirement: !ruby/object:Gem::Requirement
142
134
  requirements:
143
- - - ">="
135
+ - - "~>"
144
136
  - !ruby/object:Gem::Version
145
- version: '0'
137
+ version: '2.2'
146
138
  type: :development
147
139
  prerelease: false
148
140
  version_requirements: !ruby/object:Gem::Requirement
149
141
  requirements:
150
- - - ">="
142
+ - - "~>"
151
143
  - !ruby/object:Gem::Version
152
- version: '0'
144
+ version: '2.2'
153
145
  - !ruby/object:Gem::Dependency
154
- name: guard-rubocop
146
+ name: simplecov
155
147
  requirement: !ruby/object:Gem::Requirement
156
148
  requirements:
157
- - - ">="
149
+ - - "~>"
158
150
  - !ruby/object:Gem::Version
159
- version: '0'
151
+ version: '0.13'
160
152
  type: :development
161
153
  prerelease: false
162
154
  version_requirements: !ruby/object:Gem::Requirement
163
155
  requirements:
164
- - - ">="
156
+ - - "~>"
165
157
  - !ruby/object:Gem::Version
166
- version: '0'
158
+ version: '0.13'
167
159
  description: provides functionality for the repository or strategy pattern
168
160
  email:
169
161
  - dev@eger-andreas.de
@@ -171,15 +163,13 @@ executables: []
171
163
  extensions: []
172
164
  extra_rdoc_files: []
173
165
  files:
174
- - ".dir-locals.el"
166
+ - ".github/workflows/matrix.yml"
175
167
  - ".gitignore"
176
168
  - ".rubocop.yml"
177
- - ".travis.yml"
178
169
  - CHANGELOG.md
179
170
  - CODE_OF_CONDUCT.md
180
- - Dangerfile
181
171
  - Gemfile
182
- - Guardfile
172
+ - Gemfile.lock
183
173
  - LICENSE.txt
184
174
  - README.md
185
175
  - Rakefile
@@ -188,37 +178,32 @@ files:
188
178
  - examples/simple_repo.rb
189
179
  - lib/receptacle.rb
190
180
  - lib/receptacle/errors.rb
191
- - lib/receptacle/interface_methods.rb
192
- - lib/receptacle/method_cache.rb
193
- - lib/receptacle/method_delegation.rb
194
- - lib/receptacle/registration.rb
181
+ - lib/receptacle/repo.rb
195
182
  - lib/receptacle/test_support.rb
196
183
  - lib/receptacle/version.rb
197
- - performance/benchmark.rb
198
- - performance/profile.rb
199
- - performance/speed_receptacle.rb
200
184
  - receptacle.gemspec
185
+ - upgrade_notes.md
201
186
  homepage: https://github.com/andreaseger/receptacle
202
187
  licenses:
203
188
  - MIT
204
- metadata: {}
189
+ metadata:
190
+ rubygems_mfa_required: 'true'
205
191
  post_install_message:
206
192
  rdoc_options: []
207
193
  require_paths:
208
194
  - lib
209
195
  required_ruby_version: !ruby/object:Gem::Requirement
210
196
  requirements:
211
- - - "~>"
197
+ - - ">="
212
198
  - !ruby/object:Gem::Version
213
- version: '2.1'
199
+ version: '2.7'
214
200
  required_rubygems_version: !ruby/object:Gem::Requirement
215
201
  requirements:
216
202
  - - ">="
217
203
  - !ruby/object:Gem::Version
218
204
  version: '0'
219
205
  requirements: []
220
- rubyforge_project:
221
- rubygems_version: 2.6.11
206
+ rubygems_version: 3.4.1
222
207
  signing_key:
223
208
  specification_version: 4
224
209
  summary: repository pattern
data/.dir-locals.el DELETED
@@ -1 +0,0 @@
1
- ((ruby-mode . ( (ruby-test-runner . minitest)) ) )
data/.travis.yml DELETED
@@ -1,36 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.1.10
5
- - 2.2.6
6
- - 2.3.4
7
- - 2.4.1
8
- - jruby-9.1.12.0
9
- jdk:
10
- - oraclejdk8
11
- env:
12
- - "JRUBY_OPTS='--dev --debug'"
13
- - "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
14
- matrix:
15
- exclude:
16
- - rvm: 2.1.10
17
- jdk: oraclejdk8
18
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
19
- - rvm: 2.2.6
20
- jdk: oraclejdk8
21
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
22
- - rvm: 2.3.4
23
- jdk: oraclejdk8
24
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
25
- - rvm: 2.4.1
26
- jdk: oraclejdk8
27
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
28
- allow_failures:
29
- - rvm: jruby-9.1.12.0
30
- jdk: oraclejdk8
31
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
32
- before_install:
33
- - gem update --system
34
- - gem install bundler -v 1.15.1
35
- before_script:
36
- - bundle exec danger
data/Dangerfile DELETED
@@ -1,26 +0,0 @@
1
- # --------------------------------------------------------------------------------------------------------------------
2
- # Has any changes happened inside the actual library code?
3
- # --------------------------------------------------------------------------------------------------------------------
4
- has_app_changes = !git.modified_files.grep(/lib/).empty?
5
- has_test_changes = !git.modified_files.grep(/test/).empty?
6
- is_version_bump = git.modified_files.sort == ["CHANGELOG.md", "lib/receptacle/version.rb"].sort
7
-
8
- if has_app_changes && !has_test_changes && !is_version_bump
9
- warn("Tests were not updated. That's OK if you're refactoring existing code.", sticky: false)
10
- end
11
-
12
- if !git.modified_files.include?("CHANGELOG.md") && has_app_changes
13
- fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](https://github.com/andreaseger/receptacle/blob/master/CHANGELOG.md).")
14
- message "Note, we hard-wrap at 80 chars and use 2 spaces after the last line."
15
- end
16
-
17
- # Make it more obvious that a PR is a work in progress and shouldn't be merged yet
18
- warn("PR is classed as Work in Progress") if github.pr_title.include? "WIP"
19
-
20
- # Warn when there is a big PR
21
- warn("Big PR") if git.lines_of_code > 500
22
-
23
- commit_lint.check warn: :all, disable: [:subject_cap]
24
-
25
- # rubocop
26
- rubocop.lint
data/Guardfile DELETED
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
- # A sample Guardfile
3
- # More info at https://github.com/guard/guard#readme
4
-
5
- ## Uncomment and set this to only include directories you want to watch
6
- # directories %w(app lib config test spec features) \
7
- # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
8
-
9
- ## Note: if you are using the `directories` clause above and you are not
10
- ## watching the project directory ('.'), then you will want to move
11
- ## the Guardfile to a watched dir and symlink it back, e.g.
12
- #
13
- # $ mkdir config
14
- # $ mv Guardfile config/
15
- # $ ln -s config/Guardfile .
16
- #
17
- # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
18
- group :red_green_refactor, halt_on_fail: true do
19
- guard :minitest do
20
- # with Minitest::Unit
21
- watch(%r{^test/(.*)\/?test_(.*)\.rb$})
22
- # watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
23
- watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { 'test' }
24
- watch(%r{^test/test_helper\.rb$}) { 'test' }
25
- watch(%r{^test/fixture\.rb$}) { 'test' }
26
- end
27
- guard :rubocop, all_on_start: false, cli: ['--auto-correct'] do
28
- watch(/.+\.rb$/)
29
- watch(%r{(?:.+/)?\.rubocop\.yml%}) { |m| File.dirname(m[0]) }
30
- end
31
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'receptacle/registration'
3
- require 'receptacle/errors'
4
-
5
- module Receptacle
6
- module InterfaceMethods
7
- RESERVED_METHOD_NAMES = Set.new(%i(wrappers mediate strategy delegate_to_strategy))
8
- private_constant :RESERVED_METHOD_NAMES
9
-
10
- # registers a method_name for the to be mediated or forwarded to the configured strategy
11
- #
12
- # @param method_name [String] name of method to register
13
- def mediate(method_name)
14
- raise Errors::ReservedMethodName if RESERVED_METHOD_NAMES.include?(method_name)
15
- Registration.repositories[self].methods << method_name
16
- end
17
- alias delegate_to_strategy mediate
18
-
19
- # get or sets the strategy
20
- #
21
- # @note will set the strategy for this receptacle if passed in; will only
22
- # return the current strategy if nil or no parameter passed include
23
- # @param value [Class,nil]
24
- # @return [Class] current configured strategy class
25
- def strategy(value = nil)
26
- if value
27
- Registration.repositories[self].strategy = value
28
- Registration.clear_method_cache(self)
29
- else
30
- Registration.repositories[self].strategy
31
- end
32
- end
33
-
34
- # get or sets the wrappers
35
- #
36
- # @note will set the wrappers for this receptacle if passed in; will only
37
- # return the current wrappers if nil or no parameter passed include
38
- # @param value [Class,Array(Class),nil] wrappers
39
- # @return [Array(Class)] current configured wrappers
40
- def wrappers(value = nil)
41
- if value
42
- Registration.repositories[self].wrappers = Array(value)
43
- Registration.clear_method_cache(self)
44
- else
45
- Registration.repositories[self].wrappers
46
- end
47
- end
48
- end
49
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
- module Receptacle
3
- # Cache describing which strategy and wrappers need to be applied for this method
4
- # @api private
5
- class MethodCache
6
- # @return [Symbol] name of the method this cache belongs to
7
- attr_reader :method_name
8
- # @return [Class] strategy class currently setup
9
- attr_reader :strategy
10
- # @return [Array(Class)] Array of wrapper classes which implement a wrapper for this method
11
- attr_reader :wrappers
12
- # @return [Symbol] name of the before action method
13
- attr_reader :before_method_name
14
- # @return [Symbol] name of the after action method
15
- attr_reader :after_method_name
16
- # @return [Integer] arity of strategy method according to https://ruby-doc.org/core-2.3.3/Method.html#method-i-arity
17
- attr_reader :arity
18
-
19
- def initialize(method_name:, strategy:, wrappers:) # rubocop:disable Metrics/AbcSize
20
- @strategy = strategy
21
- @before_method_name = :"before_#{method_name}"
22
- @after_method_name = :"after_#{method_name}"
23
- @method_name = method_name.to_sym
24
- before_wrappers = wrappers.select { |w| w.method_defined?(@before_method_name) }
25
- after_wrappers = wrappers.select { |w| w.method_defined?(@after_method_name) }
26
- @wrappers = wrappers & (before_wrappers | after_wrappers)
27
- @skip_before_wrappers = before_wrappers.empty?
28
- @skip_after_wrappers = after_wrappers.empty?
29
- @arity = strategy.new.method(method_name).arity
30
- end
31
-
32
- # @return [Boolean] true if no before wrappers need to be applied for this method
33
- def skip_before_wrappers?
34
- @skip_before_wrappers
35
- end
36
-
37
- # @return [Boolean] true if no after wrappers need to be applied for this method
38
- def skip_after_wrappers?
39
- @skip_after_wrappers
40
- end
41
- end
42
- end