proxified 0.1.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +1 -0
- data/.env.remote_dev +5 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +2 -2
- data/Dockerfile +24 -4
- data/Gemfile.lock +64 -59
- data/Guardfile +3 -1
- data/README.md +119 -75
- data/bin/compose_up +4 -0
- data/bin/console +1 -0
- data/docker-compose.yml +1 -3
- data/lib/proxified/version.rb +1 -1
- data/lib/proxified.rb +477 -69
- data/proxified.gemspec +13 -9
- metadata +17 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db679149f605d627c1f13b11feb5911db64c080446fdfb79e026f17f54026610
|
4
|
+
data.tar.gz: 0d49c35b8b93dc08174945e2d3c725fc112ed16b776f7c068937f35fc5bceb68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 259fb1d8f0107a193f453e0b8cdd73fc93d37fcd96c604655ff64f89988aa5e39bc05466caa9c7635e8cbf62ff4cf18a1aaa97c37aea0c62862c46202b8f5bb3
|
7
|
+
data.tar.gz: 2a98c2d904564d26e90c69abd96ac303a89a6e5b60cb37869a38906e1b6f0d0773ddc364f2a4d7af84d0e3a09c35452c173c20f878db9456e2822a9b35f4b113
|
data/.dockerignore
CHANGED
data/.env.remote_dev
ADDED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/Dockerfile
CHANGED
@@ -1,7 +1,27 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# Base Ruby image
|
2
|
+
FROM ruby:3.3.0-slim
|
3
|
+
|
4
|
+
# Install the (minimum) required packages
|
5
|
+
RUN apt-get update -qq && apt-get install -y --fix-missing --no-install-recommends \
|
6
|
+
# Required packages for building gems etc
|
7
|
+
build-essential \
|
8
|
+
git \
|
9
|
+
# Clean apt cache
|
10
|
+
&& rm -rf /var/lib/apt/lists/*
|
11
|
+
|
12
|
+
# Base args
|
13
|
+
ARG home=/home
|
14
|
+
ARG bundle_path=/usr/local/bundle
|
15
|
+
|
16
|
+
# Set base environment variables
|
17
|
+
ENV HOME=$home \
|
18
|
+
BUNDLE_PATH=$bundle_path \
|
19
|
+
BUNDLE_APP_CONFIG=$bundle_path \
|
20
|
+
GEM_HOME=$bundle_path \
|
21
|
+
PATH=$PATH:$bundle_path/bin:$bundle_path/gems/bin
|
22
|
+
|
23
|
+
# Create base directories if do not exist
|
24
|
+
RUN mkdir -p $HOME $BUNDLE_PATH
|
5
25
|
|
6
26
|
# App user and dirs args
|
7
27
|
ARG app_name
|
data/Gemfile.lock
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
proxified (0.1
|
5
|
-
activesupport (~> 5.2
|
4
|
+
proxified (1.0.1)
|
5
|
+
activesupport (~> 5.2.4)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (5.2.
|
10
|
+
activesupport (5.2.8.1)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (>= 0.7, < 2)
|
13
13
|
minitest (~> 5.1)
|
14
14
|
tzinfo (~> 1.1)
|
15
|
-
ast (2.4.
|
16
|
-
coderay (1.1.
|
17
|
-
concurrent-ruby (1.
|
18
|
-
diff-lcs (1.
|
19
|
-
ffi (1.
|
20
|
-
formatador (
|
21
|
-
guard (2.
|
15
|
+
ast (2.4.2)
|
16
|
+
coderay (1.1.3)
|
17
|
+
concurrent-ruby (1.3.4)
|
18
|
+
diff-lcs (1.5.1)
|
19
|
+
ffi (1.17.0-x86_64-linux-gnu)
|
20
|
+
formatador (1.1.0)
|
21
|
+
guard (2.18.1)
|
22
22
|
formatador (>= 0.2.4)
|
23
23
|
listen (>= 2.7, < 4.0)
|
24
24
|
lumberjack (>= 1.0.12, < 2.0)
|
25
25
|
nenv (~> 0.1)
|
26
26
|
notiffany (~> 0.0)
|
27
|
-
pry (>= 0.
|
27
|
+
pry (>= 0.13.0)
|
28
28
|
shellany (~> 0.0)
|
29
29
|
thor (>= 0.18.1)
|
30
30
|
guard-bundler (2.2.1)
|
@@ -36,77 +36,82 @@ GEM
|
|
36
36
|
guard (~> 2.1)
|
37
37
|
guard-compat (~> 1.1)
|
38
38
|
rspec (>= 2.99.0, < 4.0)
|
39
|
-
guard-rubocop (1.
|
39
|
+
guard-rubocop (1.5.0)
|
40
40
|
guard (~> 2.0)
|
41
|
-
rubocop (
|
42
|
-
i18n (1.
|
41
|
+
rubocop (< 2.0)
|
42
|
+
i18n (1.14.6)
|
43
43
|
concurrent-ruby (~> 1.0)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
rb-
|
48
|
-
|
49
|
-
lumberjack (1.
|
50
|
-
method_source (
|
51
|
-
minitest (5.
|
44
|
+
json (2.7.2)
|
45
|
+
language_server-protocol (3.17.0.3)
|
46
|
+
listen (3.9.0)
|
47
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
48
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
49
|
+
lumberjack (1.2.10)
|
50
|
+
method_source (1.1.0)
|
51
|
+
minitest (5.25.1)
|
52
52
|
nenv (0.3.0)
|
53
|
-
notiffany (0.1.
|
53
|
+
notiffany (0.1.3)
|
54
54
|
nenv (~> 0.1)
|
55
55
|
shellany (~> 0.0)
|
56
|
-
parallel (1.
|
57
|
-
parser (
|
58
|
-
ast (~> 2.4.
|
59
|
-
|
60
|
-
pry (0.
|
61
|
-
coderay (~> 1.1
|
62
|
-
method_source (~>
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
rb-
|
56
|
+
parallel (1.26.3)
|
57
|
+
parser (3.3.5.0)
|
58
|
+
ast (~> 2.4.1)
|
59
|
+
racc
|
60
|
+
pry (0.14.2)
|
61
|
+
coderay (~> 1.1)
|
62
|
+
method_source (~> 1.0)
|
63
|
+
racc (1.8.1)
|
64
|
+
rainbow (3.1.1)
|
65
|
+
rake (12.3.3)
|
66
|
+
rb-fsevent (0.11.2)
|
67
|
+
rb-inotify (0.11.1)
|
67
68
|
ffi (~> 1.0)
|
68
|
-
|
69
|
-
|
70
|
-
rspec-
|
71
|
-
rspec-
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
regexp_parser (2.9.2)
|
70
|
+
rspec (3.13.0)
|
71
|
+
rspec-core (~> 3.13.0)
|
72
|
+
rspec-expectations (~> 3.13.0)
|
73
|
+
rspec-mocks (~> 3.13.0)
|
74
|
+
rspec-core (3.13.1)
|
75
|
+
rspec-support (~> 3.13.0)
|
76
|
+
rspec-expectations (3.13.3)
|
75
77
|
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
-
rspec-support (~> 3.
|
77
|
-
rspec-mocks (3.
|
78
|
+
rspec-support (~> 3.13.0)
|
79
|
+
rspec-mocks (3.13.1)
|
78
80
|
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
-
rspec-support (~> 3.
|
80
|
-
rspec-support (3.
|
81
|
-
rubocop (
|
82
|
-
|
81
|
+
rspec-support (~> 3.13.0)
|
82
|
+
rspec-support (3.13.1)
|
83
|
+
rubocop (1.66.1)
|
84
|
+
json (~> 2.3)
|
85
|
+
language_server-protocol (>= 3.17.0)
|
83
86
|
parallel (~> 1.10)
|
84
|
-
parser (>=
|
85
|
-
powerpack (~> 0.1)
|
87
|
+
parser (>= 3.3.0.2)
|
86
88
|
rainbow (>= 2.2.2, < 4.0)
|
89
|
+
regexp_parser (>= 2.4, < 3.0)
|
90
|
+
rubocop-ast (>= 1.32.2, < 2.0)
|
87
91
|
ruby-progressbar (~> 1.7)
|
88
|
-
unicode-display_width (
|
89
|
-
|
90
|
-
|
92
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
93
|
+
rubocop-ast (1.32.3)
|
94
|
+
parser (>= 3.3.1.0)
|
95
|
+
ruby-progressbar (1.13.0)
|
91
96
|
shellany (0.0.1)
|
92
|
-
thor (
|
97
|
+
thor (1.3.2)
|
93
98
|
thread_safe (0.3.6)
|
94
|
-
tzinfo (1.2.
|
99
|
+
tzinfo (1.2.11)
|
95
100
|
thread_safe (~> 0.1)
|
96
|
-
unicode-display_width (
|
101
|
+
unicode-display_width (2.6.0)
|
97
102
|
|
98
103
|
PLATFORMS
|
99
|
-
|
104
|
+
x86_64-linux-gnu
|
100
105
|
|
101
106
|
DEPENDENCIES
|
102
|
-
bundler (~>
|
107
|
+
bundler (~> 2.5)
|
103
108
|
guard (~> 2.15)
|
104
109
|
guard-bundler (~> 2.2, >= 2.2.1)
|
105
110
|
guard-rspec (~> 4.7, >= 4.7.3)
|
106
111
|
guard-rubocop (~> 1.3)
|
107
112
|
proxified!
|
108
|
-
rake (~>
|
113
|
+
rake (~> 12.3.3)
|
109
114
|
rspec (~> 3.8)
|
110
115
|
|
111
116
|
BUNDLED WITH
|
112
|
-
|
117
|
+
2.5.3
|
data/Guardfile
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
#
|
18
18
|
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
19
19
|
|
20
|
-
#
|
20
|
+
# NOTE: The cmd option is now required due to the increasing number of ways
|
21
21
|
# rspec may be run, below are examples of the most common uses.
|
22
22
|
# * bundler: 'bundle exec rspec'
|
23
23
|
# * bundler binstubs: 'bin/rspec'
|
@@ -48,6 +48,8 @@ group :red_green_refactor, halt_on_fail: true do
|
|
48
48
|
# Ruby files
|
49
49
|
ruby = dsl.ruby
|
50
50
|
dsl.watch_spec_files_for(ruby.lib_files)
|
51
|
+
|
52
|
+
watch(ruby.lib_files) { "#{rspec.spec_dir}/global_methods_spec.rb" }
|
51
53
|
end
|
52
54
|
|
53
55
|
guard :rubocop, all_on_start: true, cli: ['-a'] do
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/proxified.svg)](https://badge.fury.io/rb/proxified)
|
2
|
+
|
1
3
|
# Proxified
|
2
4
|
|
3
|
-
|
5
|
+
A simple way to put a proxy in front of any object, at any time.
|
4
6
|
|
5
|
-
|
7
|
+
You can add and remove a proxy to and from any object instance methods and inherit or change the behavior down the class hierarchy.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -22,114 +24,156 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
You have two options to *proxify* and *unproxify* objects:
|
28
|
+
|
29
|
+
* *statically*: if you want to put a proxy on a class while defining it, just `include Proxified` and call `proxify` with the method(s) you want to *proxify* and the code you want to run.
|
30
|
+
When you want to remove a proxy, just call `unproxify` with the method(s) you want to *unproxify*, or without methods if you want to *unproxify* all *proxified* methods.
|
31
|
+
To check if a given method is *proxified*, call `proxified?` with the method name, or without arguments to check if any instance method is *proxified*.
|
26
32
|
|
27
|
-
|
33
|
+
* *dynamically*: if you want to put a proxy on a class at runtime, or on a single object without affecting its class, call `Proxify` with the class/object and the method(s) you want to *proxify*.
|
34
|
+
Similarly, use `Unproxify` and `Proxified?` with the class/object and the method(s) you want to *unproxify*/*check*.
|
28
35
|
|
29
|
-
|
30
|
-
Similarly, a `proxified method` is removed whenever the corresponding instance method is removed from the class.
|
36
|
+
You can also mix the two approaches! (see the examples below)
|
31
37
|
|
32
|
-
|
33
|
-
|
38
|
+
In order not to change the class interface, a method is only *proxified* when the corresponding instance method is defined (before or after the proxy definition).
|
39
|
+
Similarly, a *proxified method* is removed whenever the corresponding instance method is removed from the class.
|
40
|
+
|
41
|
+
Moreover, the *proxified methods* take the arguments specified by the block, so it should take the same arguments as the original methods.
|
42
|
+
Finally, it's possible to call the actual methods invoking `super` inside the block.
|
34
43
|
|
35
44
|
```ruby
|
36
45
|
|
37
46
|
require 'proxified'
|
38
47
|
|
39
|
-
#
|
48
|
+
# Static proxy:
|
49
|
+
|
40
50
|
class A
|
41
51
|
include Proxified
|
42
52
|
|
43
|
-
proxify :
|
44
|
-
|
45
|
-
super(name)
|
53
|
+
proxify :foo, :bar, :biz do
|
54
|
+
"proxified #{super()}"
|
46
55
|
end
|
47
56
|
|
48
|
-
def
|
49
|
-
puts "checking #{name}"
|
50
|
-
end
|
57
|
+
def foo; 'foo'; end
|
51
58
|
|
52
|
-
def
|
53
|
-
puts "hello #{name}!"
|
54
|
-
end
|
59
|
+
def bar; 'bar'; end
|
55
60
|
|
56
|
-
def
|
57
|
-
|
58
|
-
end
|
61
|
+
def biz; 'biz'; end
|
62
|
+
|
63
|
+
def baz; 'baz'; end
|
59
64
|
end
|
60
65
|
|
61
|
-
|
62
|
-
a.welcome('jack') => 'checking jack'; 'welcome jack!';
|
63
|
-
a.goodbye('jack') => 'checking jack'; 'goodbye jack!';
|
64
|
-
a.welcome => raises ArgumentError
|
65
|
-
a.check('jack') => 'checking jack' # not proxified
|
66
|
+
A.ancestors # => [A::Proxy, A, Proxified, ...]
|
66
67
|
|
67
|
-
|
68
|
-
class B < A
|
69
|
-
unproxify :welcome
|
70
|
-
end
|
68
|
+
a1, a2 = A.new, A.new
|
71
69
|
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
a1.foo # => 'proxified foo'
|
71
|
+
a2.foo # => 'proxified foo'
|
72
|
+
a1.bar # => 'proxified bar'
|
73
|
+
a2.bar # => 'proxified bar'
|
74
|
+
a1.biz # => 'proxified biz'
|
75
|
+
a2.biz # => 'proxified biz'
|
76
|
+
a1.baz # => 'baz'
|
77
|
+
a2.baz # => 'baz'
|
75
78
|
|
76
79
|
|
77
|
-
#
|
78
|
-
|
79
|
-
def welcome(name)
|
80
|
-
puts "welcome #{name.upcase}!"
|
81
|
-
end
|
82
|
-
end
|
80
|
+
# unproxify the :foo method
|
81
|
+
A.unproxify(:foo) # => [:foo]
|
83
82
|
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
# the :foo method is not proxified anymore
|
84
|
+
A.proxified?(:foo) # => false
|
85
|
+
# A is still proxified, i.e. it has at least one proxified method
|
86
|
+
A.proxified? # => true
|
87
87
|
|
88
|
+
a1.foo # => 'foo'
|
89
|
+
a2.foo # => 'foo'
|
90
|
+
a1.bar # => 'proxified bar'
|
91
|
+
a2.bar # => 'proxified bar'
|
92
|
+
a1.biz # => 'proxified biz'
|
93
|
+
a2.biz # => 'proxified biz'
|
94
|
+
a1.baz # => 'baz'
|
95
|
+
a2.baz # => 'baz'
|
88
96
|
|
89
|
-
# Reproxifing a proxified method:
|
90
|
-
class D < A
|
91
|
-
proxify :welcome do |name|
|
92
|
-
super(name.upcase)
|
93
|
-
end
|
94
|
-
end
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
-
d.goodbye('jack') => 'checking jack'; 'goodbye jack!';
|
98
|
+
# unproxify all the methods
|
99
|
+
A.unproxify # => [:bar, :biz]
|
99
100
|
|
101
|
+
# A is not proxified anymore
|
102
|
+
A.proxified? # => false
|
100
103
|
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
104
|
+
a1.foo # => 'foo'
|
105
|
+
a2.foo # => 'foo'
|
106
|
+
a1.bar # => 'bar'
|
107
|
+
a2.bar # => 'bar'
|
108
|
+
a1.biz # => 'biz'
|
109
|
+
a2.biz # => 'biz'
|
110
|
+
a1.baz # => 'baz'
|
111
|
+
a2.baz # => 'baz'
|
106
112
|
|
107
|
-
def welcome(name)
|
108
|
-
puts "hello #{name}!"
|
109
|
-
end
|
110
|
-
end
|
111
113
|
|
112
|
-
|
113
|
-
e.welcome('jack') => 'hello JACK!';
|
114
|
-
e.goodbye('jack') => 'checking jack'; 'goodbye jack!';
|
114
|
+
# Dynamic proxy:
|
115
115
|
|
116
|
+
# on a class
|
117
|
+
Proxify(A, :foo, :bar) { 'proxified again' } # => [:foo, :bar]
|
116
118
|
|
117
|
-
#
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
119
|
+
a1.foo # => 'proxified again'
|
120
|
+
a2.foo # => 'proxified again'
|
121
|
+
a1.bar # => 'proxified again'
|
122
|
+
a2.bar # => 'proxified again'
|
123
|
+
a1.biz # => 'biz'
|
124
|
+
a2.biz # => 'biz'
|
125
|
+
a1.baz # => 'baz'
|
126
|
+
a2.baz # => 'baz'
|
127
|
+
|
128
|
+
|
129
|
+
# on a single object
|
130
|
+
Proxify(a1, :bar, :biz) { 'singleton proxy' } # => [:bar, :biz]
|
131
|
+
|
132
|
+
a1.foo # => 'proxified again'
|
133
|
+
a2.foo # => 'proxified again'
|
134
|
+
a1.bar # => 'singleton proxy'
|
135
|
+
a2.bar # => 'proxified again'
|
136
|
+
a1.biz # => 'singleton proxy'
|
137
|
+
a2.biz # => 'biz'
|
138
|
+
a1.baz # => 'baz'
|
139
|
+
a2.baz # => 'baz'
|
140
|
+
|
141
|
+
|
142
|
+
# unproxify all the methods of a1
|
143
|
+
Unproxify(a1) # => [:foo, :bar, :biz]
|
144
|
+
|
145
|
+
# still proxified because of the class' proxy
|
146
|
+
Proxified?(a1) # => true
|
147
|
+
|
148
|
+
a1.foo # => 'proxified again'
|
149
|
+
a2.foo # => 'proxified again'
|
150
|
+
a1.bar # => 'proxified again'
|
151
|
+
a2.bar # => 'proxified again'
|
152
|
+
a1.biz # => 'biz'
|
153
|
+
a2.biz # => 'biz'
|
154
|
+
a1.baz # => 'baz'
|
155
|
+
a2.baz # => 'baz'
|
156
|
+
|
157
|
+
|
158
|
+
# unproxify all the methods of A
|
159
|
+
Unproxify(A, :foo, :bar) # => [:foo, :bar]
|
160
|
+
|
161
|
+
a1.foo # => 'foo'
|
162
|
+
a2.foo # => 'foo'
|
163
|
+
a1.bar # => 'bar'
|
164
|
+
a2.bar # => 'bar'
|
165
|
+
a1.biz # => 'biz'
|
166
|
+
a2.biz # => 'biz'
|
167
|
+
a1.baz # => 'baz'
|
168
|
+
a2.baz # => 'baz'
|
125
169
|
|
126
|
-
f = F.new
|
127
|
-
f.welcome('jack') => 'checking jack'; 'checking jack'; 'welcome jack!'; 'hi';
|
128
|
-
f.goodbye('jack') => 'checking jack'; 'goodbye jack!';
|
129
170
|
```
|
171
|
+
|
172
|
+
Just look at the code documentation to see more examples of what you can/cannot do.
|
173
|
+
|
130
174
|
## Notes
|
131
175
|
|
132
|
-
This is my first gem, something I extracted from a bigger project and a first attempt to give back
|
176
|
+
This is my first gem, something I extracted from a bigger project and a first attempt to give something back to the community.
|
133
177
|
|
134
178
|
Any constructive feedback is welcome and appreciated, thank you!
|
135
179
|
|
data/bin/compose_up
ADDED
data/bin/console
CHANGED
data/docker-compose.yml
CHANGED
data/lib/proxified/version.rb
CHANGED