tacky 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.0pdd.yml +0 -3
- data/.github/workflows/pdd.yml +11 -0
- data/.github/workflows/rake.yml +23 -0
- data/.github/workflows/xcop.yml +11 -0
- data/.rubocop.yml +6 -2
- data/.rultor.yml +4 -6
- data/Gemfile +7 -2
- data/LICENSE.txt +1 -1
- data/README.md +8 -7
- data/Rakefile +1 -1
- data/lib/tacky.rb +10 -6
- data/renovate.json +6 -0
- data/tacky.gemspec +4 -13
- data/test/test_tacky.rb +51 -2
- metadata +12 -80
- 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: 5f9e870d165e0ece19499a198839f511b75099a011371bd352056b885b100fd1
|
4
|
+
data.tar.gz: 8d6410ebaf0654c87abaf09c7897c0d1f45e7cb62a0f0f9d6be6e300e4f08597
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dd984f23d799f5b889f7809c5b2e8ebbeee4c48a97a561e5cffea3943573ec6b87b38b73a5fcce66a2eec1b298a206544da35e7053132d42a8f18edaa543f0e
|
7
|
+
data.tar.gz: e31cc8fe917be002b9f0d3aa37e7c53888072ecd03f9680089e40f58b07194c2fa954c9aaa520304f4b29e19aec0f9a8a6aefddd907e384f894e27bfd2f49077
|
data/.0pdd.yml
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
name: rake
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
jobs:
|
11
|
+
test:
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
os: [ubuntu-20.04]
|
15
|
+
ruby: ['3.0']
|
16
|
+
runs-on: ${{ matrix.os }}
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v3
|
19
|
+
- uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
- run: bundle update
|
23
|
+
- run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
AllCops:
|
2
2
|
DisplayCopNames: true
|
3
3
|
TargetRubyVersion: 2.3
|
4
|
+
NewCops: enable
|
5
|
+
SuggestExtensions: false
|
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,10 @@
|
|
1
|
+
docker:
|
2
|
+
image: yegor256/rultor-image:1.20.0
|
1
3
|
assets:
|
2
4
|
rubygems.yml: yegor256/home#assets/rubygems.yml
|
3
5
|
install: |-
|
4
|
-
|
5
|
-
|
6
|
+
sudo gem install openssl -- --with-openssl-dir=/usr/local/rvm/rubies/ruby-3.0.1/lib/ruby/3.0.0/openssl
|
7
|
+
pdd -f /dev/null
|
6
8
|
sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
|
7
9
|
release:
|
8
10
|
script: |-
|
@@ -18,7 +20,3 @@ merge:
|
|
18
20
|
script: |-
|
19
21
|
bundle install
|
20
22
|
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,10 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
source 'https://rubygems.org'
|
24
|
-
ruby '~>2.3'
|
25
24
|
gemspec
|
25
|
+
|
26
|
+
gem 'minitest', '5.18.1', require: false
|
27
|
+
gem 'rake', '13.0.6', require: false
|
28
|
+
gem 'rdoc', '6.5.0', require: false
|
29
|
+
gem 'rubocop', '1.52.1', require: false
|
30
|
+
gem 'rubocop-rspec', '2.22.0', require: false
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -4,12 +4,10 @@
|
|
4
4
|
[![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/tacky)](http://www.rultor.com/p/yegor256/tacky)
|
5
5
|
[![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
|
6
6
|
|
7
|
-
[![
|
8
|
-
[![Build status](https://ci.appveyor.com/api/projects/status/e61qudqccs0fu8xt?svg=true)](https://ci.appveyor.com/project/yegor256/tacky)
|
7
|
+
[![rake](https://github.com/yegor256/tacky/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/tacky/actions/workflows/rake.yml)
|
9
8
|
[![Gem Version](https://badge.fury.io/rb/tacky.svg)](http://badge.fury.io/rb/tacky)
|
10
9
|
[![Maintainability](https://api.codeclimate.com/v1/badges/224939b58aa606fdd56c/maintainability)](https://codeclimate.com/github/yegor256/tacky/maintainability)
|
11
10
|
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/tacky/master/frames)
|
12
|
-
|
13
11
|
[![Hits-of-Code](https://hitsofcode.com/github/yegor256/tacky)](https://hitsofcode.com/view/github/yegor256/tacky)
|
14
12
|
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/tacky/blob/master/LICENSE.txt)
|
15
13
|
|
@@ -26,17 +24,20 @@ require 'tacky'
|
|
26
24
|
obj = Tacky.new(obj)
|
27
25
|
```
|
28
26
|
|
29
|
-
That's it, all method calls will be cached.
|
27
|
+
That's it, all method calls will be cached. This means that only the first
|
28
|
+
call of any method will actually reach your object. All consecutive calls
|
29
|
+
will be intercepted by the `Tacky` decorator, which will return
|
30
|
+
previously calculated values. The decorator keeps all values in its internal
|
31
|
+
`Hash`.
|
30
32
|
|
31
|
-
If you want all methods of everything your methods return be cached, you
|
33
|
+
If you want all methods of everything your methods return be cached too, you
|
32
34
|
need to use "deep" caching (it's `true` by default):
|
33
35
|
|
34
|
-
|
35
36
|
```ruby
|
36
37
|
obj = Tacky.new(obj, deep: true)
|
37
38
|
```
|
38
39
|
|
39
|
-
`Tacky` is thread-safe.
|
40
|
+
Keep in mind that `Tacky` is thread-safe.
|
40
41
|
|
41
42
|
## How to contribute
|
42
43
|
|
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
|
data/lib/tacky.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,13 +29,19 @@
|
|
29
29
|
# {README}[https://github.com/yegor256/tacky/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 Tacky
|
35
35
|
undef_method :send
|
36
36
|
|
37
37
|
# Deep nesting will stop at these classes.
|
38
|
-
STOP = [
|
38
|
+
STOP = [
|
39
|
+
Numeric, NilClass,
|
40
|
+
TrueClass, FalseClass,
|
41
|
+
Array, Hash,
|
42
|
+
Time,
|
43
|
+
String
|
44
|
+
].freeze
|
39
45
|
|
40
46
|
def initialize(origin, deep: true)
|
41
47
|
@origin = origin
|
@@ -50,9 +56,7 @@ class Tacky
|
|
50
56
|
@cache[args] = @origin.__send__(*args) do |*a|
|
51
57
|
yield(*a) if block_given?
|
52
58
|
end
|
53
|
-
if @deep && STOP.none? { |t| @cache[args].is_a?(t) }
|
54
|
-
@cache[args] = Tacky.new(@cache[args], deep: @deep)
|
55
|
-
end
|
59
|
+
@cache[args] = Tacky.new(@cache[args], deep: @deep) if @deep && STOP.none? { |t| @cache[args].is_a?(t) }
|
56
60
|
end
|
57
61
|
@cache[args]
|
58
62
|
end
|
data/renovate.json
ADDED
data/tacky.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 = 'tacky'
|
34
|
-
s.version = '0.
|
30
|
+
s.version = '0.4.0'
|
35
31
|
s.license = 'MIT'
|
36
32
|
s.summary = 'Primitive Object Memoization for Ruby'
|
37
33
|
s.description = 'Decorate your existing Ruby object with Tacky
|
@@ -40,12 +36,7 @@ and all its methods will be cached.'
|
|
40
36
|
s.email = 'yegor256@gmail.com'
|
41
37
|
s.homepage = 'http://github.com/yegor256/tacky'
|
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.1'
|
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
|
data/test/test_tacky.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
|
@@ -27,7 +27,7 @@ require_relative '../lib/tacky'
|
|
27
27
|
|
28
28
|
# Tacky test.
|
29
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2020 Yegor Bugayenko
|
30
|
+
# Copyright:: Copyright (c) 2020-2023 Yegor Bugayenko
|
31
31
|
# License:: MIT
|
32
32
|
class TackyTest < Minitest::Test
|
33
33
|
def test_wraps_simple_object
|
@@ -54,4 +54,53 @@ class TackyTest < Minitest::Test
|
|
54
54
|
assert(first.is_a?(Numeric))
|
55
55
|
assert(bar.child.value == first)
|
56
56
|
end
|
57
|
+
|
58
|
+
def test_stops_on_string
|
59
|
+
foo = Object.new
|
60
|
+
def foo.value
|
61
|
+
'hello'
|
62
|
+
end
|
63
|
+
bar = Tacky.new(foo)
|
64
|
+
assert(bar.value.is_a?(String))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_wraps_void_returning_methods
|
68
|
+
foo = Class.new do
|
69
|
+
attr_reader :done
|
70
|
+
|
71
|
+
def initialize
|
72
|
+
@done = 0
|
73
|
+
end
|
74
|
+
|
75
|
+
def touch
|
76
|
+
@done += 1
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
end.new
|
80
|
+
bar = Tacky.new(foo)
|
81
|
+
bar.touch
|
82
|
+
bar.touch
|
83
|
+
assert_equal(1, foo.done)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_diff_methods_by_params
|
87
|
+
foo = Object.new
|
88
|
+
def foo.value(val)
|
89
|
+
val
|
90
|
+
end
|
91
|
+
bar = Tacky.new(foo)
|
92
|
+
assert_equal(5, bar.value(5))
|
93
|
+
assert_equal(10, bar.value(10))
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_diff_methods_by_hash_params
|
97
|
+
foo = Object.new
|
98
|
+
def foo.value(*)
|
99
|
+
rand(1000)
|
100
|
+
end
|
101
|
+
bar = Tacky.new(foo)
|
102
|
+
assert_equal(bar.value(val: 5), bar.value(val: 5))
|
103
|
+
assert_equal(bar.value(val: 10), bar.value(val: 10))
|
104
|
+
assert_equal(bar.value(val: true), bar.value(val: true))
|
105
|
+
end
|
57
106
|
end
|
metadata
CHANGED
@@ -1,85 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tacky
|
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.1
|
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.1
|
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-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
83
13
|
description: |-
|
84
14
|
Decorate your existing Ruby object with Tacky
|
85
15
|
and all its methods will be cached.
|
@@ -90,24 +20,27 @@ extra_rdoc_files:
|
|
90
20
|
- README.md
|
91
21
|
files:
|
92
22
|
- ".0pdd.yml"
|
23
|
+
- ".github/workflows/pdd.yml"
|
24
|
+
- ".github/workflows/rake.yml"
|
25
|
+
- ".github/workflows/xcop.yml"
|
93
26
|
- ".gitignore"
|
94
27
|
- ".pdd"
|
95
28
|
- ".rubocop.yml"
|
96
29
|
- ".rultor.yml"
|
97
|
-
- ".travis.yml"
|
98
30
|
- Gemfile
|
99
31
|
- LICENSE.txt
|
100
32
|
- README.md
|
101
33
|
- Rakefile
|
102
|
-
- appveyor.yml
|
103
34
|
- lib/tacky.rb
|
104
35
|
- logo.svg
|
36
|
+
- renovate.json
|
105
37
|
- tacky.gemspec
|
106
38
|
- test/test_tacky.rb
|
107
39
|
homepage: http://github.com/yegor256/tacky
|
108
40
|
licenses:
|
109
41
|
- MIT
|
110
|
-
metadata:
|
42
|
+
metadata:
|
43
|
+
rubygems_mfa_required: 'true'
|
111
44
|
post_install_message:
|
112
45
|
rdoc_options:
|
113
46
|
- "--charset=UTF-8"
|
@@ -124,9 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
57
|
- !ruby/object:Gem::Version
|
125
58
|
version: '0'
|
126
59
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
60
|
+
rubygems_version: 3.2.15
|
128
61
|
signing_key:
|
129
|
-
specification_version:
|
62
|
+
specification_version: 4
|
130
63
|
summary: Primitive Object Memoization for Ruby
|
131
|
-
test_files:
|
132
|
-
- test/test_tacky.rb
|
64
|
+
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
|