veils 0.2.0 → 0.4.0
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 +4 -4
- data/.github/workflows/codecov.yml +20 -0
- data/.github/workflows/pdd.yml +11 -0
- data/.github/workflows/rake.yml +24 -0
- data/.github/workflows/xcop.yml +11 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -2
- data/.rultor.yml +3 -6
- data/Gemfile +8 -2
- data/README.md +25 -5
- data/Rakefile +1 -3
- data/lib/alterin.rb +69 -0
- data/lib/alterout.rb +70 -0
- data/lib/unpiercable.rb +4 -6
- data/lib/veil.rb +4 -6
- data/renovate.json +6 -0
- data/test/test__helper.rb +30 -0
- data/test/test_alterin.rb +56 -0
- data/test/test_alterout.rb +56 -0
- data/test/test_unpiercable.rb +19 -5
- data/test/test_veil.rb +16 -2
- data/veils.gemspec +4 -13
- metadata +18 -81
- data/.travis.yml +0 -12
- data/appveyor.yml +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f513329bb84443c3a8a723560a6632155e7a615e5600184ea35e2ac78d9a2cf
|
4
|
+
data.tar.gz: 99da05320c58895c4c2ea5b0a9475ae26436198cdcfa81a8f6d739a0aa52966e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bf4e67e4d20f8d0dbd3357a0dac91efe30d73c336dd6ad7042b6a9ebb1591589b283df5974585ce206034dd91a8272729dd2e0462023a0b2fae65f22269e58e
|
7
|
+
data.tar.gz: 0fe108e9065d2854139b1d63801b186e361f91d182f4343e98804d4edd9b15801c101db569eecc69e87a3a3f7d76b293586a7588f0e117aa827ed53506dd49bb
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
name: codecov
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
jobs:
|
8
|
+
codecov:
|
9
|
+
runs-on: ubuntu-20.04
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v3
|
12
|
+
- uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: 2.7
|
15
|
+
- run: bundle update
|
16
|
+
- run: bundle exec rake
|
17
|
+
- uses: codecov/codecov-action@v3
|
18
|
+
with:
|
19
|
+
file: coverage/.resultset.json
|
20
|
+
fail_ci_if_error: true
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
name: rake
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
jobs:
|
11
|
+
test:
|
12
|
+
name: test
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
os: [ubuntu-20.04, macos-12]
|
16
|
+
ruby: [2.7, 3.2]
|
17
|
+
runs-on: ${{ matrix.os }}
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v3
|
20
|
+
- uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
23
|
+
- run: bundle update
|
24
|
+
- run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
AllCops:
|
2
2
|
DisplayCopNames: true
|
3
3
|
TargetRubyVersion: 2.3
|
4
|
+
SuggestExtensions: false
|
5
|
+
NewCops: enable
|
4
6
|
|
5
7
|
Layout/EndOfLine:
|
6
8
|
EnforcedStyle: lf
|
7
|
-
|
9
|
+
Lint/MissingSuper:
|
8
10
|
Enabled: false
|
9
11
|
Layout/EmptyLineAfterGuardClause:
|
10
12
|
Enabled: false
|
@@ -24,5 +26,7 @@ Metrics/PerceivedComplexity:
|
|
24
26
|
Max: 10
|
25
27
|
Metrics/ParameterLists:
|
26
28
|
Max: 10
|
27
|
-
Layout/
|
29
|
+
Layout/ParameterAlignment:
|
30
|
+
Enabled: false
|
31
|
+
Style/OptionalBooleanParameter:
|
28
32
|
Enabled: false
|
data/.rultor.yml
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
docker:
|
2
|
+
image: yegor256/rultor-image:1.19.0
|
1
3
|
assets:
|
2
4
|
rubygems.yml: yegor256/home#assets/rubygems.yml
|
3
5
|
install: |-
|
4
|
-
|
5
|
-
export GEM_PATH=$GEM_HOME:$GEM_PATH
|
6
|
+
pdd -f /dev/null
|
6
7
|
sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
|
7
8
|
release:
|
8
9
|
script: |-
|
@@ -18,7 +19,3 @@ merge:
|
|
18
19
|
script: |-
|
19
20
|
bundle install
|
20
21
|
bundle exec rake
|
21
|
-
deploy:
|
22
|
-
script: |-
|
23
|
-
echo 'Nothing to deploy'
|
24
|
-
exit -1
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2020 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -21,5 +21,11 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
source 'https://rubygems.org'
|
24
|
-
ruby '~>2.3'
|
25
24
|
gemspec
|
25
|
+
|
26
|
+
gem 'minitest', '5.18.0', require: false
|
27
|
+
gem 'rake', '13.0.6', require: false
|
28
|
+
gem 'rdoc', '6.5.0', require: false
|
29
|
+
gem 'rubocop', '1.51.0', require: false
|
30
|
+
gem 'rubocop-rspec', '2.22.0', require: false
|
31
|
+
gem 'simplecov', '0.22.0', require: false
|
data/README.md
CHANGED
@@ -4,15 +4,16 @@
|
|
4
4
|
[](http://www.rultor.com/p/yegor256/veils)
|
5
5
|
[](https://www.jetbrains.com/ruby/)
|
6
6
|
|
7
|
-
[](https://ci.appveyor.com/project/yegor256/veils)
|
7
|
+
[](https://github.com/yegor256/veils/actions/workflows/rake.yml)
|
9
8
|
[](http://badge.fury.io/rb/veils)
|
10
9
|
[](https://codeclimate.com/github/yegor256/veils/maintainability)
|
11
10
|
[](http://rubydoc.info/github/yegor256/veils/master/frames)
|
12
|
-
|
13
11
|
[](https://hitsofcode.com/view/github/yegor256/veils)
|
14
12
|
[](https://github.com/yegor256/veils/blob/master/LICENSE.txt)
|
15
13
|
|
14
|
+
Read this blog post first:
|
15
|
+
[Veil Objects to Replace DTOs](https://www.yegor256.com/2020/05/19/veil-objects.html)
|
16
|
+
|
16
17
|
First, install it:
|
17
18
|
|
18
19
|
```bash
|
@@ -22,14 +23,33 @@ $ gem install veils
|
|
22
23
|
Then, use it like this:
|
23
24
|
|
24
25
|
```ruby
|
25
|
-
require '
|
26
|
+
require 'veil'
|
26
27
|
obj = Veil.new(obj, to_s: 'Hello, world!')
|
27
28
|
```
|
28
29
|
|
29
30
|
The method `to_s` will return `Hello, world!` until some other
|
30
31
|
method is called and the veil is "pierced."
|
31
32
|
|
32
|
-
|
33
|
+
You can also use `Unpiercable` decorator, which will never be pierced:
|
34
|
+
a very good instrument for data memoization.
|
35
|
+
|
36
|
+
You can also try `AlterOut`, which lets you modify the output
|
37
|
+
of object methods on fly:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'alterout'
|
41
|
+
obj = AlterOut.new(obj, to_s: proc { |s| s + 'extra tail' })
|
42
|
+
```
|
43
|
+
|
44
|
+
There is also `AlterIn` decorator, to modify incoming method arguments
|
45
|
+
(the result of the `proc` will replace the list of input arguments):
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'alterin'
|
49
|
+
obj = AlterIn.new(obj, print: proc { |i| [i + 1] })
|
50
|
+
```
|
51
|
+
|
52
|
+
Keep in mind that all classes are thread-safe.
|
33
53
|
|
34
54
|
## How to contribute
|
35
55
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2020 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -24,8 +24,6 @@ require 'rubygems'
|
|
24
24
|
require 'rake'
|
25
25
|
require 'rake/clean'
|
26
26
|
|
27
|
-
CLEAN = FileList['coverage']
|
28
|
-
|
29
27
|
def name
|
30
28
|
@name ||= File.basename(Dir['*.gemspec'].first, '.*')
|
31
29
|
end
|
data/lib/alterin.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
# Decorator to modify method inputs.
|
26
|
+
#
|
27
|
+
# For more information read
|
28
|
+
# {README}[https://github.com/yegor256/veils/blob/master/README.md] file.
|
29
|
+
#
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2020-2023 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
class AlterIn
|
34
|
+
def initialize(origin, methods = {})
|
35
|
+
@origin = origin
|
36
|
+
@methods = methods
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
method_missing(:to_s)
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_json(options = nil)
|
44
|
+
return @origin.to_a.to_json(options) if @origin.is_a?(Array)
|
45
|
+
method_missing(:to_json, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def method_missing(*args)
|
49
|
+
method = args[0]
|
50
|
+
raise "Method #{method} is absent in #{@origin}" unless @origin.respond_to?(method)
|
51
|
+
inputs = args[1..-1]
|
52
|
+
inputs = @methods[method].call(inputs) if @methods.key?(method)
|
53
|
+
if block_given?
|
54
|
+
@origin.__send__(*([method] + inputs)) do |*a|
|
55
|
+
yield(*a)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
@origin.__send__(*([method] + inputs))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def respond_to?(method, include_private = false)
|
63
|
+
@origin.respond_to?(method, include_private) || @methods.key?(method)
|
64
|
+
end
|
65
|
+
|
66
|
+
def respond_to_missing?(_method, _include_private = false)
|
67
|
+
true
|
68
|
+
end
|
69
|
+
end
|
data/lib/alterout.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
# Decorator to modify method outputs.
|
26
|
+
#
|
27
|
+
# For more information read
|
28
|
+
# {README}[https://github.com/yegor256/veils/blob/master/README.md] file.
|
29
|
+
#
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2020-2023 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
class AlterOut
|
34
|
+
def initialize(origin, methods = {})
|
35
|
+
@origin = origin
|
36
|
+
@methods = methods
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
method_missing(:to_s)
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_json(options = nil)
|
44
|
+
return @origin.to_a.to_json(options) if @origin.is_a?(Array)
|
45
|
+
method_missing(:to_json, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def method_missing(*args)
|
49
|
+
method = args[0]
|
50
|
+
raise "Method #{method} is absent in #{@origin}" unless @origin.respond_to?(method)
|
51
|
+
out =
|
52
|
+
if block_given?
|
53
|
+
@origin.__send__(*args) do |*a|
|
54
|
+
yield(*a)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
@origin.__send__(*args)
|
58
|
+
end
|
59
|
+
out = @methods[method].call(out) if @methods.key?(method)
|
60
|
+
out
|
61
|
+
end
|
62
|
+
|
63
|
+
def respond_to?(method, include_private = false)
|
64
|
+
@origin.respond_to?(method, include_private) || @methods.key?(method)
|
65
|
+
end
|
66
|
+
|
67
|
+
def respond_to_missing?(_method, _include_private = false)
|
68
|
+
true
|
69
|
+
end
|
70
|
+
end
|
data/lib/unpiercable.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2020 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -29,7 +29,7 @@
|
|
29
29
|
# {README}[https://github.com/yegor256/veils/blob/master/README.md] file.
|
30
30
|
#
|
31
31
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
32
|
-
# Copyright:: Copyright (c) 2020 Yegor Bugayenko
|
32
|
+
# Copyright:: Copyright (c) 2020-2023 Yegor Bugayenko
|
33
33
|
# License:: MIT
|
34
34
|
class Unpiercable
|
35
35
|
def initialize(origin, methods = {})
|
@@ -51,9 +51,7 @@ class Unpiercable
|
|
51
51
|
if @methods.key?(method)
|
52
52
|
@methods[method]
|
53
53
|
else
|
54
|
-
unless @origin.respond_to?(method)
|
55
|
-
raise "Method #{method} is absent in #{@origin}"
|
56
|
-
end
|
54
|
+
raise "Method #{method} is absent in #{@origin}" unless @origin.respond_to?(method)
|
57
55
|
if block_given?
|
58
56
|
@origin.__send__(*args) do |*a|
|
59
57
|
yield(*a)
|
@@ -65,7 +63,7 @@ class Unpiercable
|
|
65
63
|
end
|
66
64
|
|
67
65
|
def respond_to?(method, include_private = false)
|
68
|
-
@origin.respond_to?(method, include_private) || @methods
|
66
|
+
@origin.respond_to?(method, include_private) || @methods.key?(method)
|
69
67
|
end
|
70
68
|
|
71
69
|
def respond_to_missing?(_method, _include_private = false)
|
data/lib/veil.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2020 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -29,7 +29,7 @@
|
|
29
29
|
# {README}[https://github.com/yegor256/veils/blob/master/README.md] file.
|
30
30
|
#
|
31
31
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
32
|
-
# Copyright:: Copyright (c) 2020 Yegor Bugayenko
|
32
|
+
# Copyright:: Copyright (c) 2020-2023 Yegor Bugayenko
|
33
33
|
# License:: MIT
|
34
34
|
class Veil
|
35
35
|
def initialize(origin, methods = {})
|
@@ -51,9 +51,7 @@ class Veil
|
|
51
51
|
method = args[0]
|
52
52
|
if @pierced || !@methods.key?(method)
|
53
53
|
@pierced = true
|
54
|
-
unless @origin.respond_to?(method)
|
55
|
-
raise "Method #{method} is absent in #{@origin}"
|
56
|
-
end
|
54
|
+
raise "Method #{method} is absent in #{@origin}" unless @origin.respond_to?(method)
|
57
55
|
if block_given?
|
58
56
|
@origin.__send__(*args) do |*a|
|
59
57
|
yield(*a)
|
@@ -67,7 +65,7 @@ class Veil
|
|
67
65
|
end
|
68
66
|
|
69
67
|
def respond_to?(method, include_private = false)
|
70
|
-
@origin.respond_to?(method, include_private) || @methods
|
68
|
+
@origin.respond_to?(method, include_private) || @methods.key?(method)
|
71
69
|
end
|
72
70
|
|
73
71
|
def respond_to_missing?(_method, _include_private = false)
|
data/renovate.json
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
$stdout.sync = true
|
26
|
+
|
27
|
+
require 'simplecov'
|
28
|
+
SimpleCov.start
|
29
|
+
|
30
|
+
require 'minitest/autorun'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require 'json'
|
27
|
+
require_relative '../lib/alterin'
|
28
|
+
|
29
|
+
# AlterIn test.
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2020-2023 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
class AlterInTest < Minitest::Test
|
34
|
+
def test_simple
|
35
|
+
obj = Object.new
|
36
|
+
def obj.plus(first, second)
|
37
|
+
first + second
|
38
|
+
end
|
39
|
+
foo = AlterIn.new(obj, plus: proc { |a, b| [a + 1, b + 1] })
|
40
|
+
assert_equal(7, foo.plus(2, 3))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_respond_to
|
44
|
+
foo = AlterIn.new(Object.new)
|
45
|
+
assert_equal(false, foo.respond_to?(:undefine_method))
|
46
|
+
|
47
|
+
foo = AlterIn.new(Object.new, method_return_object: Object.new)
|
48
|
+
assert_equal(true, foo.respond_to?(:method_return_object))
|
49
|
+
|
50
|
+
foo = AlterIn.new(Object.new, method_return_false: false)
|
51
|
+
assert_equal(true, foo.respond_to?(:method_return_false))
|
52
|
+
|
53
|
+
foo = AlterIn.new(Object.new, method_return_nil: nil)
|
54
|
+
assert_equal(true, foo.respond_to?(:method_return_nil))
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require 'json'
|
27
|
+
require_relative '../lib/alterout'
|
28
|
+
|
29
|
+
# AlterOut test.
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2020-2023 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
class AlterOutTest < Minitest::Test
|
34
|
+
def test_simple
|
35
|
+
obj = Object.new
|
36
|
+
def obj.read(val)
|
37
|
+
val
|
38
|
+
end
|
39
|
+
foo = AlterOut.new(obj, read: proc { |r| r + 1 })
|
40
|
+
assert_equal(6, foo.read(5))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_respond_to
|
44
|
+
foo = AlterOut.new(Object.new)
|
45
|
+
assert_equal(false, foo.respond_to?(:undefine_method))
|
46
|
+
|
47
|
+
foo = AlterOut.new(Object.new, method_return_object: Object.new)
|
48
|
+
assert_equal(true, foo.respond_to?(:method_return_object))
|
49
|
+
|
50
|
+
foo = AlterOut.new(Object.new, method_return_false: false)
|
51
|
+
assert_equal(true, foo.respond_to?(:method_return_false))
|
52
|
+
|
53
|
+
foo = AlterOut.new(Object.new, method_return_nil: nil)
|
54
|
+
assert_equal(true, foo.respond_to?(:method_return_nil))
|
55
|
+
end
|
56
|
+
end
|
data/test/test_unpiercable.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2020 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -24,13 +24,13 @@
|
|
24
24
|
|
25
25
|
require 'minitest/autorun'
|
26
26
|
require 'json'
|
27
|
-
require_relative '../lib/
|
27
|
+
require_relative '../lib/unpiercable'
|
28
28
|
|
29
29
|
# Veil test.
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
-
# Copyright:: Copyright (c) 2020 Yegor Bugayenko
|
31
|
+
# Copyright:: Copyright (c) 2020-2023 Yegor Bugayenko
|
32
32
|
# License:: MIT
|
33
|
-
class
|
33
|
+
class UnpiercableTest < Minitest::Test
|
34
34
|
def test_simple
|
35
35
|
obj = Object.new
|
36
36
|
def obj.read(foo)
|
@@ -42,7 +42,7 @@ class VeilTest < Minitest::Test
|
|
42
42
|
assert_equal(1, foo.read(5))
|
43
43
|
foo.to_s
|
44
44
|
foo.touch
|
45
|
-
assert_equal(
|
45
|
+
assert_equal(1, foo.read(5))
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_behaves_like_array_with_json
|
@@ -71,4 +71,18 @@ class VeilTest < Minitest::Test
|
|
71
71
|
foo.each { |_| observed += 1 }
|
72
72
|
assert_equal(3, observed)
|
73
73
|
end
|
74
|
+
|
75
|
+
def test_respond_to
|
76
|
+
foo = Unpiercable.new(Object.new)
|
77
|
+
assert_equal(false, foo.respond_to?(:undefine_method))
|
78
|
+
|
79
|
+
foo = Unpiercable.new(Object.new, method_return_object: Object.new)
|
80
|
+
assert_equal(true, foo.respond_to?(:method_return_object))
|
81
|
+
|
82
|
+
foo = Unpiercable.new(Object.new, method_return_false: false)
|
83
|
+
assert_equal(true, foo.respond_to?(:method_return_false))
|
84
|
+
|
85
|
+
foo = Unpiercable.new(Object.new, method_return_nil: nil)
|
86
|
+
assert_equal(true, foo.respond_to?(:method_return_nil))
|
87
|
+
end
|
74
88
|
end
|
data/test/test_veil.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2020 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -28,7 +28,7 @@ require_relative '../lib/veil'
|
|
28
28
|
|
29
29
|
# Veil test.
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
-
# Copyright:: Copyright (c) 2020 Yegor Bugayenko
|
31
|
+
# Copyright:: Copyright (c) 2020-2023 Yegor Bugayenko
|
32
32
|
# License:: MIT
|
33
33
|
class VeilTest < Minitest::Test
|
34
34
|
def test_simple
|
@@ -71,4 +71,18 @@ class VeilTest < Minitest::Test
|
|
71
71
|
foo.each { |_| observed += 1 }
|
72
72
|
assert_equal(3, observed)
|
73
73
|
end
|
74
|
+
|
75
|
+
def test_respond_to
|
76
|
+
foo = Veil.new(Object.new)
|
77
|
+
assert_equal(false, foo.respond_to?(:undefine_method))
|
78
|
+
|
79
|
+
foo = Veil.new(Object.new, method_return_object: Object.new)
|
80
|
+
assert_equal(true, foo.respond_to?(:method_return_object))
|
81
|
+
|
82
|
+
foo = Veil.new(Object.new, method_return_false: false)
|
83
|
+
assert_equal(true, foo.respond_to?(:method_return_false))
|
84
|
+
|
85
|
+
foo = Veil.new(Object.new, method_return_nil: nil)
|
86
|
+
assert_equal(true, foo.respond_to?(:method_return_nil))
|
87
|
+
end
|
74
88
|
end
|
data/veils.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2020 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2020-2023 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -24,14 +24,10 @@
|
|
24
24
|
|
25
25
|
require 'English'
|
26
26
|
Gem::Specification.new do |s|
|
27
|
-
s.
|
28
|
-
if s.respond_to? :required_rubygems_version=
|
29
|
-
s.required_rubygems_version = Gem::Requirement.new('>= 0')
|
30
|
-
end
|
31
|
-
s.rubygems_version = '2.3.3'
|
27
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
32
28
|
s.required_ruby_version = '>=2.3'
|
33
29
|
s.name = 'veils'
|
34
|
-
s.version = '0.
|
30
|
+
s.version = '0.4.0'
|
35
31
|
s.license = 'MIT'
|
36
32
|
s.summary = 'Ruby Veil Objects'
|
37
33
|
s.description = 'Decorate your existing Ruby object with veils
|
@@ -40,12 +36,7 @@ and some its methods will be cached.'
|
|
40
36
|
s.email = 'yegor256@gmail.com'
|
41
37
|
s.homepage = 'http://github.com/yegor256/veils'
|
42
38
|
s.files = `git ls-files`.split($RS)
|
43
|
-
s.test_files = s.files.grep(%r{^(test)/})
|
44
39
|
s.rdoc_options = ['--charset=UTF-8']
|
45
40
|
s.extra_rdoc_files = ['README.md']
|
46
|
-
s.
|
47
|
-
s.add_development_dependency 'rake', '12.3.3'
|
48
|
-
s.add_development_dependency 'rdoc', '4.3.0'
|
49
|
-
s.add_development_dependency 'rubocop', '0.62.0'
|
50
|
-
s.add_development_dependency 'rubocop-rspec', '1.31.0'
|
41
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
51
42
|
end
|
metadata
CHANGED
@@ -1,85 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: veils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: minitest
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 5.11.3
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 5.11.3
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 12.3.3
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 12.3.3
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rdoc
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 4.3.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 4.3.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.62.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.62.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop-rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 1.31.0
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.31.0
|
11
|
+
date: 2023-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
83
13
|
description: |-
|
84
14
|
Decorate your existing Ruby object with veils
|
85
15
|
and some its methods will be cached.
|
@@ -90,26 +20,35 @@ extra_rdoc_files:
|
|
90
20
|
- README.md
|
91
21
|
files:
|
92
22
|
- ".0pdd.yml"
|
23
|
+
- ".github/workflows/codecov.yml"
|
24
|
+
- ".github/workflows/pdd.yml"
|
25
|
+
- ".github/workflows/rake.yml"
|
26
|
+
- ".github/workflows/xcop.yml"
|
93
27
|
- ".gitignore"
|
94
28
|
- ".pdd"
|
95
29
|
- ".rubocop.yml"
|
96
30
|
- ".rultor.yml"
|
97
|
-
- ".travis.yml"
|
98
31
|
- Gemfile
|
99
32
|
- LICENSE.txt
|
100
33
|
- README.md
|
101
34
|
- Rakefile
|
102
|
-
-
|
35
|
+
- lib/alterin.rb
|
36
|
+
- lib/alterout.rb
|
103
37
|
- lib/unpiercable.rb
|
104
38
|
- lib/veil.rb
|
105
39
|
- logo.svg
|
40
|
+
- renovate.json
|
41
|
+
- test/test__helper.rb
|
42
|
+
- test/test_alterin.rb
|
43
|
+
- test/test_alterout.rb
|
106
44
|
- test/test_unpiercable.rb
|
107
45
|
- test/test_veil.rb
|
108
46
|
- veils.gemspec
|
109
47
|
homepage: http://github.com/yegor256/veils
|
110
48
|
licenses:
|
111
49
|
- MIT
|
112
|
-
metadata:
|
50
|
+
metadata:
|
51
|
+
rubygems_mfa_required: 'true'
|
113
52
|
post_install_message:
|
114
53
|
rdoc_options:
|
115
54
|
- "--charset=UTF-8"
|
@@ -126,10 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
65
|
- !ruby/object:Gem::Version
|
127
66
|
version: '0'
|
128
67
|
requirements: []
|
129
|
-
rubygems_version: 3.
|
68
|
+
rubygems_version: 3.2.15
|
130
69
|
signing_key:
|
131
|
-
specification_version:
|
70
|
+
specification_version: 4
|
132
71
|
summary: Ruby Veil Objects
|
133
|
-
test_files:
|
134
|
-
- test/test_unpiercable.rb
|
135
|
-
- test/test_veil.rb
|
72
|
+
test_files: []
|
data/.travis.yml
DELETED
data/appveyor.yml
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
version: '{build}'
|
2
|
-
skip_tags: true
|
3
|
-
clone_depth: 10
|
4
|
-
branches:
|
5
|
-
only:
|
6
|
-
- master
|
7
|
-
except:
|
8
|
-
- gh-pages
|
9
|
-
os: Windows Server 2012
|
10
|
-
environment:
|
11
|
-
matrix:
|
12
|
-
- ruby_version: "25-x64"
|
13
|
-
install:
|
14
|
-
- ps: |
|
15
|
-
$Env:PATH = "C:\Ruby${Env:ruby_version}\bin;${Env:PATH}"
|
16
|
-
- bundle config --local path vendor/bundle
|
17
|
-
- ruby -v
|
18
|
-
- bundle -v
|
19
|
-
build_script:
|
20
|
-
- bundle update
|
21
|
-
- bundle install
|
22
|
-
test_script:
|
23
|
-
- bundle exec rake --quiet
|
24
|
-
cache:
|
25
|
-
- vendor/bundle
|