receptacle 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -8
- data/CHANGELOG.md +11 -5
- data/Dangerfile +26 -0
- data/Gemfile +6 -0
- data/Guardfile +2 -1
- data/lib/receptacle/method_cache.rb +3 -0
- data/lib/receptacle/method_delegation.rb +38 -13
- data/lib/receptacle/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de42650ef4891b4f5cadb6a0ca4c357a8499b338
|
4
|
+
data.tar.gz: 9b266f6ed5637ae89aee2e5c9053ab0963015ca7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 239ef17fba657fc3ccf5a87b01f840f8d6de7646bbee4daa3ca8e284c97137b7c348b7bc0069cd1e970df19062ccb13ff91b6922a02c6a763b434393b90e6187
|
7
|
+
data.tar.gz: d49b157c7427025e36aaf55ed1d0cbe878a6463723654b1de000c0272dfc72ecccaa61323b9907414a9b1811ee8ef9bfaa91c4dba345c6a2548440e0786112a4
|
data/.travis.yml
CHANGED
@@ -9,27 +9,28 @@ rvm:
|
|
9
9
|
jdk:
|
10
10
|
- oraclejdk8
|
11
11
|
env:
|
12
|
-
- "JRUBY_OPTS='--dev'"
|
13
|
-
- "JRUBY_OPTS='-Xcompile.invokedynamic=true'"
|
12
|
+
- "JRUBY_OPTS='--dev --debug'"
|
13
|
+
- "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
|
14
14
|
matrix:
|
15
15
|
exclude:
|
16
16
|
- rvm: 2.1.10
|
17
17
|
jdk: oraclejdk8
|
18
|
-
env: "JRUBY_OPTS='-Xcompile.invokedynamic=true'"
|
18
|
+
env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
|
19
19
|
- rvm: 2.2.6
|
20
20
|
jdk: oraclejdk8
|
21
|
-
env: "JRUBY_OPTS='-Xcompile.invokedynamic=true'"
|
21
|
+
env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
|
22
22
|
- rvm: 2.3.3
|
23
23
|
jdk: oraclejdk8
|
24
|
-
env: "JRUBY_OPTS='-Xcompile.invokedynamic=true'"
|
24
|
+
env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
|
25
25
|
- rvm: 2.4.0
|
26
26
|
jdk: oraclejdk8
|
27
|
-
env: "JRUBY_OPTS='-Xcompile.invokedynamic=true'"
|
27
|
+
env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
|
28
28
|
allow_failures:
|
29
29
|
- rvm: jruby-9.1.7.0
|
30
30
|
jdk: oraclejdk8
|
31
|
-
env: "JRUBY_OPTS='-Xcompile.invokedynamic=true'"
|
32
|
-
|
31
|
+
env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
|
33
32
|
before_install:
|
34
33
|
- gem update --system
|
35
34
|
- gem install bundler -v 1.14.3
|
35
|
+
before_script:
|
36
|
+
- bundle exec danger
|
data/CHANGELOG.md
CHANGED
@@ -4,20 +4,26 @@ Changelog
|
|
4
4
|
master
|
5
5
|
---
|
6
6
|
|
7
|
+
0.3.0
|
8
|
+
---
|
9
|
+
|
10
|
+
* add danger
|
11
|
+
* also support higher arity methods (== method with more than one argument)
|
12
|
+
|
7
13
|
0.2.0
|
8
14
|
---
|
9
15
|
|
10
|
-
|
11
|
-
|
16
|
+
* update documentation
|
17
|
+
* enable ruby 2.1+
|
12
18
|
|
13
19
|
0.1.1
|
14
20
|
---
|
15
21
|
|
16
|
-
|
17
|
-
|
22
|
+
* add changelog, update copyright
|
23
|
+
* add test helper method `ensure_method_delegators` to make rspec stubs/mocks work as expected
|
18
24
|
|
19
25
|
0.1.0
|
20
26
|
---
|
21
27
|
|
22
|
-
|
28
|
+
* initial release
|
23
29
|
|
data/Dangerfile
ADDED
@@ -0,0 +1,26 @@
|
|
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/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -19,7 +19,8 @@ group :red_green_refactor, halt_on_fail: true do
|
|
19
19
|
guard :minitest do
|
20
20
|
# with Minitest::Unit
|
21
21
|
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
|
22
|
-
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
22
|
+
# watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
23
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { 'test' }
|
23
24
|
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
24
25
|
watch(%r{^test/fixture\.rb$}) { 'test' }
|
25
26
|
end
|
@@ -13,6 +13,8 @@ module Receptacle
|
|
13
13
|
attr_reader :before_method_name
|
14
14
|
# @return [Symbol] name of the after action method
|
15
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
|
16
18
|
|
17
19
|
def initialize(method_name:, strategy:, before_wrappers:, after_wrappers:)
|
18
20
|
@strategy = strategy
|
@@ -24,6 +26,7 @@ module Receptacle
|
|
24
26
|
@wrappers = before_wrappers | after_wrappers
|
25
27
|
@skip_before_wrappers = before_wrappers.empty?
|
26
28
|
@skip_after_wrappers = after_wrappers.empty?
|
29
|
+
@arity = strategy.new.method(method_name).arity
|
27
30
|
end
|
28
31
|
|
29
32
|
# @return [Boolean] true if no before wrappers need to be applied for this method
|
@@ -26,6 +26,8 @@ module Receptacle
|
|
26
26
|
method_cache = __build_method_call_cache(method_name)
|
27
27
|
if method_cache.wrappers.nil? || method_cache.wrappers.empty?
|
28
28
|
__define_shortcut_method(method_cache)
|
29
|
+
elsif method_cache.arity.abs > 1
|
30
|
+
__define_full_method_high_arity(method_cache)
|
29
31
|
else
|
30
32
|
__define_full_method(method_cache)
|
31
33
|
end
|
@@ -57,7 +59,7 @@ module Receptacle
|
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
|
-
# build method to mediate method calls to strategy with full wrapper support
|
62
|
+
# build method to mediate method calls of arity 1 to strategy with full wrapper support
|
61
63
|
# @param method_cache [MethodCache] method_cache of the method to be build
|
62
64
|
# @return [void]
|
63
65
|
def __define_full_method(method_cache)
|
@@ -68,31 +70,49 @@ module Receptacle
|
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
73
|
+
# build method to mediate method calls of higher arity to strategy with full wrapper support
|
74
|
+
# @param method_cache [MethodCache] method_cache of the method to be build
|
75
|
+
# @return [void]
|
76
|
+
def __define_full_method_high_arity(method_cache)
|
77
|
+
define_singleton_method(method_cache.method_name) do |*args, &inner_block|
|
78
|
+
__run_wrappers(method_cache, args, true) do |*call_args|
|
79
|
+
method_cache.strategy.new.public_send(method_cache.method_name, *call_args, &inner_block)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
71
84
|
# runtime method to call before and after wrapper in correct order
|
72
85
|
# @param method_cache [MethodCache] method_cache for the current method
|
73
86
|
# @param input_args input parameter of the repository method call
|
87
|
+
# @param high_arity [Boolean] if are intended for a higher arity method
|
74
88
|
# @return strategy method return value after all wrappers where applied
|
75
|
-
def __run_wrappers(method_cache, input_args)
|
89
|
+
def __run_wrappers(method_cache, input_args, high_arity = false)
|
76
90
|
wrappers = method_cache.wrappers.map(&:new)
|
77
|
-
args =
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
91
|
+
args =
|
92
|
+
if method_cache.skip_before_wrappers?
|
93
|
+
input_args
|
94
|
+
else
|
95
|
+
__run_before_wrappers(wrappers, method_cache.before_method_name, input_args, high_arity)
|
96
|
+
end
|
97
|
+
ret = high_arity ? yield(*args) : yield(args)
|
83
98
|
return ret if method_cache.skip_after_wrappers?
|
84
|
-
__run_after_wrappers(wrappers, method_cache.after_method_name, args, ret)
|
99
|
+
__run_after_wrappers(wrappers, method_cache.after_method_name, args, ret, high_arity)
|
85
100
|
end
|
86
101
|
|
87
102
|
# runtime method to execute all before wrappers
|
88
103
|
# @param wrappers [Array] all wrapper instances to be executed
|
89
104
|
# @param method_name [Symbol] name of method to be executed on wrappers
|
90
105
|
# @param args input args of the repository method
|
106
|
+
# @param high_arity [Boolean] if are intended for a higher arity method
|
91
107
|
# @return processed method args by before wrappers
|
92
|
-
def __run_before_wrappers(wrappers, method_name, args)
|
108
|
+
def __run_before_wrappers(wrappers, method_name, args, high_arity = false)
|
93
109
|
wrappers.each do |wrapper|
|
94
110
|
next unless wrapper.respond_to?(method_name)
|
95
|
-
args =
|
111
|
+
args = if high_arity
|
112
|
+
wrapper.public_send(method_name, *args)
|
113
|
+
else
|
114
|
+
wrapper.public_send(method_name, args)
|
115
|
+
end
|
96
116
|
end
|
97
117
|
args
|
98
118
|
end
|
@@ -102,11 +122,16 @@ module Receptacle
|
|
102
122
|
# @param method_name [Symbol] name of method to be executed on wrappers
|
103
123
|
# @param args input args to the strategy method (after processing in before wrappers)
|
104
124
|
# @param return_value return value of strategy method
|
125
|
+
# @param high_arity [Boolean] if are intended for a higher arity method
|
105
126
|
# @return processed return value by all after wrappers
|
106
|
-
def __run_after_wrappers(wrappers, method_name, args, return_value)
|
127
|
+
def __run_after_wrappers(wrappers, method_name, args, return_value, high_arity = false)
|
107
128
|
wrappers.reverse_each do |wrapper|
|
108
129
|
next unless wrapper.respond_to?(method_name)
|
109
|
-
return_value =
|
130
|
+
return_value = if high_arity
|
131
|
+
wrapper.public_send(method_name, return_value, *args)
|
132
|
+
else
|
133
|
+
wrapper.public_send(method_name, return_value, args)
|
134
|
+
end
|
110
135
|
end
|
111
136
|
return_value
|
112
137
|
end
|
data/lib/receptacle/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: receptacle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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-02-
|
11
|
+
date: 2017-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- ".travis.yml"
|
178
178
|
- CHANGELOG.md
|
179
179
|
- CODE_OF_CONDUCT.md
|
180
|
+
- Dangerfile
|
180
181
|
- Gemfile
|
181
182
|
- Guardfile
|
182
183
|
- LICENSE.txt
|