proxified 0.1.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd5b3ded355bfb619efec1c6a3314498662945cd1ca2e36d2b38ae71823a0bb6
4
- data.tar.gz: e16834d5a79ab0cd7d5b38b40ed7e7f7af2203c37b84c569e90f33a57ebd6c18
3
+ metadata.gz: db679149f605d627c1f13b11feb5911db64c080446fdfb79e026f17f54026610
4
+ data.tar.gz: 0d49c35b8b93dc08174945e2d3c725fc112ed16b776f7c068937f35fc5bceb68
5
5
  SHA512:
6
- metadata.gz: 56ba529f8c836164dd010395d7311511bcce0123dd482574585e3327bc66060f1a512984379397f148f73cbcc0d66efae98d3ff1cf54133eb0d269ef1c93ec41
7
- data.tar.gz: c7553667d0ff27a830d315a33c44d7a5b257451a7d53201e0dadb13507a419cc4e0e331e1667977503b3032ba0391e614b92f97b63f66d877c605f6798640324
6
+ metadata.gz: 259fb1d8f0107a193f453e0b8cdd73fc93d37fcd96c604655ff64f89988aa5e39bc05466caa9c7635e8cbf62ff4cf18a1aaa97c37aea0c62862c46202b8f5bb3
7
+ data.tar.gz: 2a98c2d904564d26e90c69abd96ac303a89a6e5b60cb37869a38906e1b6f0d0773ddc364f2a4d7af84d0e3a09c35452c173c20f878db9456e2822a9b35f4b113
data/.dockerignore CHANGED
@@ -2,6 +2,7 @@
2
2
  docker-compose.yml
3
3
  Dockerfile
4
4
  .env
5
+ .env.remote_dev
5
6
 
6
7
  log
7
8
  tmp
data/.env.remote_dev ADDED
@@ -0,0 +1,5 @@
1
+ # environment variables for docker-compose
2
+ COMPOSE_PROJECT_NAME=gem-proxified
3
+ APP_NAME=gem-proxified
4
+ BUNDLE_PATH=/home/gem-proxified/bundle
5
+ REPO_PATH=/home/gem-proxified/repo
data/.rubocop.yml CHANGED
@@ -1,5 +1,13 @@
1
+ AllCops:
2
+
3
+ TargetRubyVersion: '3.3'
1
4
  Metrics/BlockLength:
2
5
  Exclude:
6
+ - lib/proxified.rb
3
7
  - spec/**/*
4
8
  - Guardfile
5
9
  - proxified.gemspec
10
+
11
+ Naming/MethodName:
12
+ Exclude:
13
+ - lib/proxified.rb
data/.travis.yml CHANGED
@@ -3,5 +3,5 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.6.0
7
- before_install: gem install bundler -v 1.17.2
6
+ - 3.3.0
7
+ before_install: gem install bundler -v 2.5.3
data/Dockerfile CHANGED
@@ -1,7 +1,27 @@
1
- # Build args for base image
2
- ARG bundle_path
3
- # Base image with the tools to build a ruby gem
4
- FROM awruby:gems
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.0)
5
- activesupport (~> 5.2, >= 5.2.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.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.0)
16
- coderay (1.1.2)
17
- concurrent-ruby (1.1.4)
18
- diff-lcs (1.3)
19
- ffi (1.10.0)
20
- formatador (0.2.5)
21
- guard (2.15.0)
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.9.12)
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.3.0)
39
+ guard-rubocop (1.5.0)
40
40
  guard (~> 2.0)
41
- rubocop (~> 0.20)
42
- i18n (1.5.3)
41
+ rubocop (< 2.0)
42
+ i18n (1.14.6)
43
43
  concurrent-ruby (~> 1.0)
44
- jaro_winkler (1.5.2)
45
- listen (3.1.5)
46
- rb-fsevent (~> 0.9, >= 0.9.4)
47
- rb-inotify (~> 0.9, >= 0.9.7)
48
- ruby_dep (~> 1.2)
49
- lumberjack (1.0.13)
50
- method_source (0.9.2)
51
- minitest (5.11.3)
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.1)
53
+ notiffany (0.1.3)
54
54
  nenv (~> 0.1)
55
55
  shellany (~> 0.0)
56
- parallel (1.13.0)
57
- parser (2.6.0.0)
58
- ast (~> 2.4.0)
59
- powerpack (0.1.2)
60
- pry (0.12.2)
61
- coderay (~> 1.1.0)
62
- method_source (~> 0.9.0)
63
- rainbow (3.0.0)
64
- rake (10.5.0)
65
- rb-fsevent (0.10.3)
66
- rb-inotify (0.10.0)
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
- rspec (3.8.0)
69
- rspec-core (~> 3.8.0)
70
- rspec-expectations (~> 3.8.0)
71
- rspec-mocks (~> 3.8.0)
72
- rspec-core (3.8.0)
73
- rspec-support (~> 3.8.0)
74
- rspec-expectations (3.8.2)
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.8.0)
77
- rspec-mocks (3.8.0)
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.8.0)
80
- rspec-support (3.8.0)
81
- rubocop (0.63.1)
82
- jaro_winkler (~> 1.5.1)
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 (>= 2.5, != 2.5.1.1)
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 (~> 1.4.0)
89
- ruby-progressbar (1.10.0)
90
- ruby_dep (1.5.0)
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 (0.20.3)
97
+ thor (1.3.2)
93
98
  thread_safe (0.3.6)
94
- tzinfo (1.2.5)
99
+ tzinfo (1.2.11)
95
100
  thread_safe (~> 0.1)
96
- unicode-display_width (1.4.1)
101
+ unicode-display_width (2.6.0)
97
102
 
98
103
  PLATFORMS
99
- ruby
104
+ x86_64-linux-gnu
100
105
 
101
106
  DEPENDENCIES
102
- bundler (~> 1.17)
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 (~> 10.0)
113
+ rake (~> 12.3.3)
109
114
  rspec (~> 3.8)
110
115
 
111
116
  BUNDLED WITH
112
- 1.17.2
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
- # Note: The cmd option is now required due to the increasing number of ways
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
- Proxify any object with a few lines of code.
5
+ A simple way to put a proxy in front of any object, at any time.
4
6
 
5
- A simple way to add (and remove) a proxy to any object's instance methods and to inherit and change the behaviour down the class hierarchy.
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
- Just `include Proxified` in your class and call `proxify` with the method(s) you want to proxify and the code you want to run.
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
- If you want to remove a proxy, just call `unproxify` with the method(s) you want to unproxify.
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
- In order to not change the class interface, a method is only `proxified` when the corresponding instance method is defined (before or after the proxy definition).
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
- Moreover, the `proxified methods` take the arguments specified by the `block`, so it should take the same arguments as the original `methods`.
33
- Finally, it's possible to call the actual `methods` invoking `super` inside the `block`.
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
- # Basic usage:
48
+ # Static proxy:
49
+
40
50
  class A
41
51
  include Proxified
42
52
 
43
- proxify :welcome, :goodbye do |name|
44
- check(name)
45
- super(name)
53
+ proxify :foo, :bar, :biz do
54
+ "proxified #{super()}"
46
55
  end
47
56
 
48
- def check(name)
49
- puts "checking #{name}"
50
- end
57
+ def foo; 'foo'; end
51
58
 
52
- def welcome(name)
53
- puts "hello #{name}!"
54
- end
59
+ def bar; 'bar'; end
55
60
 
56
- def goodbye(name)
57
- puts "goodbye #{name}!"
58
- end
61
+ def biz; 'biz'; end
62
+
63
+ def baz; 'baz'; end
59
64
  end
60
65
 
61
- a = A.new
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
- # Unproxifing a proxified method:
68
- class B < A
69
- unproxify :welcome
70
- end
68
+ a1, a2 = A.new, A.new
71
69
 
72
- b = B.new
73
- b.welcome('jack') => 'welcome jack!';
74
- b.goodbye('jack') => 'checking jack'; 'goodbye jack!';
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
- # Redefining a proxified method:
78
- class C < A
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
- c = C.new
85
- c.welcome('jack') => 'checking jack'; 'welcome JACK!';
86
- c.goodbye('jack') => 'checking jack'; 'goodbye jack!';
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
- d = D.new
97
- d.welcome('jack') => 'checking JACK'; 'welcome JACK!';
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
- # Reproxifing and redefining a proxified method:
102
- class E < A
103
- proxify :welcome do |name|
104
- super(name.upcase)
105
- end
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
- e = E.new
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
- # Redefining a proxified method to call super:
118
- class F < A
119
- def welcome(name)
120
- # Will call F's proxy, then A's proxy and finally A's method
121
- super(name)
122
- puts 'hi'
123
- end
124
- end
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 something to the community.
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
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # shortcut with necessary args in remote dev envs (e.g. env-file)
4
+ docker compose -f "docker-compose.yml" --env-file ".env.remote_dev" up -d --build
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'proxified'
data/docker-compose.yml CHANGED
@@ -1,5 +1,3 @@
1
- version: "3.7"
2
-
3
1
  services:
4
2
  app:
5
3
  build:
@@ -12,7 +10,7 @@ services:
12
10
  - bundle:$BUNDLE_PATH
13
11
  tty: true
14
12
  guard:
15
- image: "${APP_NAME}_app:latest"
13
+ image: "${APP_NAME}-app:latest"
16
14
  volumes:
17
15
  - .:$REPO_PATH
18
16
  - bundle:$BUNDLE_PATH
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Proxified
4
- VERSION = '0.1.0'.freeze
4
+ VERSION = '1.0.1'
5
5
  end