syncem 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5761e6992463f8579483a2b08eceec8a322aaac1e7474a77b161a47919655311
4
- data.tar.gz: 825171250d56b5e20e4b139058b4cfddf44edc8882dcced73ac71f2fe72994c8
3
+ metadata.gz: 717e4aacf4dedf530e9310ff99bc1093133b7ed37d852e671d1c0030cd8e05a9
4
+ data.tar.gz: '0329b04fc3a58177996e3d0a168cc64a71e9d288d95bda071fd4b80d5c8c5353'
5
5
  SHA512:
6
- metadata.gz: 41b7696bbb9cd74832e1e6c0cc6255ef3d3c0d815d3c177aa51cbfb449f1d3985ca25065c0ab36aea39d9e4e25b5d078d813a7a0bbedea4b58ac0a6c09217679
7
- data.tar.gz: adce504a8e497df4b2bbb372a5c9dc19e64003c81d523778d4b459e6cb16b978e59cb708ce6a7bc943213bdfdb5888c30df72f197772122ec9236b29ff14d509
6
+ metadata.gz: 8f13ad393602d6b0c0709161f5afd2ea099cea06624bb53534beed841c28b9ed8e35f2e4f525eb7dd30dca2e4229f5b78f92501220f9b466bfd6f9c562b86918
7
+ data.tar.gz: 9dded723a7d571ea66d2f8ffdaca24d18cccbce5adb694c0e4206e191e03ef3863c3d60c57b22c75e541f857d8d364dd1d95a6ac3c84184e7f4ddb3f6246227c
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: codecov
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ jobs:
8
+ codecov:
9
+ runs-on: ubuntu-22.04
10
+ steps:
11
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
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@v4
18
+ with:
19
+ file: coverage/.resultset.json
20
+ fail_ci_if_error: true
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: pdd
3
+ on:
4
+ push:
5
+ pull_request:
6
+ jobs:
7
+ pdd:
8
+ runs-on: ubuntu-22.04
9
+ steps:
10
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
11
+ - uses: g4s8/pdd-action@master
@@ -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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ - run: bundle update
24
+ - run: bundle exec rake
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: xcop
3
+ on:
4
+ push:
5
+ pull_request:
6
+ jobs:
7
+ xcop:
8
+ runs-on: ubuntu-22.04
9
+ steps:
10
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
11
+ - uses: g4s8/xcop-action@master
data/.rubocop.yml CHANGED
@@ -1,26 +1,21 @@
1
1
  AllCops:
2
2
  DisplayCopNames: true
3
3
  TargetRubyVersion: 2.3
4
+ SuggestExtensions: false
5
+ NewCops: enable
4
6
 
5
- Layout/EmptyLineAfterGuardClause:
6
- Enabled: false
7
- Layout/MultilineMethodCallIndentation:
8
- Enabled: false
9
7
  Layout/EndOfLine:
10
8
  EnforcedStyle: lf
11
- Metrics/AbcSize:
12
- Max: 65
13
- Metrics/BlockLength:
14
- Max: 30
15
9
  Metrics/MethodLength:
16
10
  Max: 50
17
- Metrics/ClassLength:
18
- Max: 180
11
+ Layout/ParameterAlignment:
12
+ Enabled: false
13
+ Style/OptionalBooleanParameter:
14
+ Enabled: false
19
15
  Metrics/CyclomaticComplexity:
20
16
  Max: 10
21
17
  Metrics/PerceivedComplexity:
22
18
  Max: 10
23
- Metrics/ParameterLists:
24
- Max: 10
25
- Layout/AlignParameters:
26
- Enabled: false
19
+ Metrics/AbcSize:
20
+ Max: 25
21
+
data/.rultor.yml CHANGED
@@ -1,11 +1,14 @@
1
+ docker:
2
+ image: yegor256/rultor-image:1.22.0
1
3
  assets:
2
- rubygems.yml: zerocracy/home#assets/rubygems.yml
3
- install: |-
4
- export GEM_HOME=~/.ruby
5
- export GEM_PATH=$GEM_HOME:$GEM_PATH
4
+ rubygems.yml: yegor256/home#assets/rubygems.yml
5
+ install: |
6
+ sudo gem install pdd
7
+ pdd -f /dev/null
8
+ sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
6
9
  release:
10
+ pre: false
7
11
  script: |-
8
- bundle install
9
12
  bundle exec rake
10
13
  rm -rf *.gem
11
14
  sed -i "s/0\.0\.0/${tag}/g" syncem.gemspec
@@ -14,13 +17,6 @@ release:
14
17
  gem build syncem.gemspec
15
18
  chmod 0600 ../rubygems.yml
16
19
  gem push *.gem --config-file ../rubygems.yml
17
- commanders:
18
- - yegor256
19
- architect:
20
- - yegor256
21
20
  merge:
22
- commanders: []
23
21
  script: |-
24
- bundle install
25
- rake
26
- deploy: {}
22
+ bundle exec rake
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2019 Yegor Bugayenko
3
+ # Copyright (c) 2018-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
+ gem 'minitest', '5.20.0', require: false
26
+ gem 'rake', '13.1.0', require: false
27
+ gem 'rdoc', '6.6.0', require: false
28
+ gem 'rubocop', '1.57.2', require: false
29
+ gem 'rubocop-rspec', '2.25.0', require: false
30
+ gem 'threads', '0.4.0', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included
13
+ in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,19 +1,26 @@
1
- [![EO principles respected here](http://www.elegantobjects.org/badge.svg)](http://www.elegantobjects.org)
1
+ <img src="/logo.svg" width="64px" height="64px"/>
2
+
3
+ [![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)
2
4
  [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/syncem)](http://www.rultor.com/p/yegor256/syncem)
3
- [![We recommend RubyMine](http://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
5
+ [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
4
6
 
5
- [![Build Status](https://travis-ci.org/yegor256/syncem.svg)](https://travis-ci.org/yegor256/syncem)
6
- [![Build status](https://ci.appveyor.com/api/projects/status/po1mn8ca96jk0llr?svg=true)](https://ci.appveyor.com/project/yegor256/syncem)
7
+ [![rake](https://github.com/yegor256/syncem/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/syncem/actions/workflows/rake.yml)
7
8
  [![Gem Version](https://badge.fury.io/rb/syncem.svg)](http://badge.fury.io/rb/syncem)
8
9
  [![Maintainability](https://api.codeclimate.com/v1/badges/5528e182bb5e4a2ecc1f/maintainability)](https://codeclimate.com/github/yegor256/syncem/maintainability)
9
10
  [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/syncem/master/frames)
11
+ [![Hits-of-Code](https://hitsofcode.com/github/yegor256/syncem)](https://hitsofcode.com/view/github/yegor256/syncem)
12
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/syncem/blob/master/LICENSE.txt)
13
+
14
+ Read this blog post:
15
+ [_SyncEm: Thread-Safe Decorators in Ruby_](https://www.yegor256.com/2019/06/26/syncem.html).
10
16
 
11
17
  Sometimes you have an object that is not thread-safe,
12
18
  but you need to make sure each of its methods is thread-safe, because they
13
19
  deal with some resources, like files or databases and you want them to
14
20
  manage those resources sequentially. This small gem will help you achieve
15
21
  exactly that without any re-design of the objects you already have. Just
16
- decorate them with `SyncEm` decorator and that is it.
22
+ decorate them with `SyncEm` [thread-safe decorator](https://www.yegor256.com/2017/01/17/synchronized-decorators.html)
23
+ and that is it.
17
24
 
18
25
  First, install it:
19
26
 
@@ -30,7 +37,7 @@ obj = SyncEm.new(obj)
30
37
 
31
38
  That's it.
32
39
 
33
- # How to contribute
40
+ ## How to contribute
34
41
 
35
42
  Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
36
43
  Make sure you build is green before you contribute
@@ -39,31 +46,7 @@ your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2
39
46
 
40
47
  ```
41
48
  $ bundle update
42
- $ rake
49
+ $ bundle exec rake
43
50
  ```
44
51
 
45
52
  If it's clean and you don't see any error messages, submit your pull request.
46
-
47
- # License
48
-
49
- (The MIT License)
50
-
51
- Copyright (c) 2018-2019 Yegor Bugayenko
52
-
53
- Permission is hereby granted, free of charge, to any person obtaining a copy
54
- of this software and associated documentation files (the 'Software'), to deal
55
- in the Software without restriction, including without limitation the rights
56
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
57
- copies of the Software, and to permit persons to whom the Software is
58
- furnished to do so, subject to the following conditions:
59
-
60
- The above copyright notice and this permission notice shall be included in all
61
- copies or substantial portions of the Software.
62
-
63
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
64
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
65
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
66
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
67
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
68
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
69
- SOFTWARE.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2019 Yegor Bugayenko
3
+ # Copyright (c) 2018-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/syncem.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # (The MIT License)
4
4
  #
5
- # Copyright (c) 2018-2019 Yegor Bugayenko
5
+ # Copyright (c) 2018-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,9 +29,11 @@
29
29
  # {README}[https://github.com/yegor256/syncem/blob/master/README.md] file.
30
30
  #
31
31
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
- # Copyright:: Copyright (c) 2018-2019 Yegor Bugayenko
32
+ # Copyright:: Copyright (c) 2018-2023 Yegor Bugayenko
33
33
  # License:: MIT
34
34
  class SyncEm
35
+ undef_method :send
36
+
35
37
  def initialize(origin)
36
38
  @origin = origin
37
39
  @mutex = Mutex.new
@@ -39,9 +41,18 @@ class SyncEm
39
41
 
40
42
  def method_missing(*args)
41
43
  @mutex.synchronize do
42
- if @origin.respond_to?(args[0])
43
- @origin.send(*args) do |*a|
44
- yield(*a) if block_given?
44
+ mtd = args.shift
45
+ if @origin.respond_to?(mtd)
46
+ params = @origin.method(mtd).parameters
47
+ reqs = params.count { |p| p[0] == :req }
48
+ if params.any? { |p| p[0] == :key } && args.size > reqs
49
+ @origin.__send__(mtd, *args[0...-1], **args.last) do |*a|
50
+ yield(*a) if block_given?
51
+ end
52
+ else
53
+ @origin.__send__(mtd, *args) do |*a|
54
+ yield(*a) if block_given?
55
+ end
45
56
  end
46
57
  else
47
58
  super
data/logo.svg ADDED
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="314px" height="314px" viewBox="0 0 314 314" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <!-- Generator: Sketch 43.2 (39069) - http://www.bohemiancoding.com/sketch -->
4
+ <title>Group 2</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <defs></defs>
7
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
8
+ <g id="Group-2">
9
+ <g id="Group">
10
+ <circle id="Oval" fill="#053C5E" cx="157" cy="157" r="157"></circle>
11
+ <rect id="Rectangle" fill="#2B2B2B" x="0" y="234" width="237" height="68"></rect>
12
+ <text id="syncem" font-family="CourierNewPS-BoldMT, Courier New" font-size="50" font-weight="bold" fill="#FFFFFF">
13
+ <tspan x="28" y="282">syncem</tspan>
14
+ </text>
15
+ <path d="M135.676765,111.215287 C135.211714,113.540467 132.770932,120.688823 130.252813,127.100603 C127.734621,133.512383 125.2898,140.431445 124.819828,142.476214 C123.6868,147.405663 121.517836,147.185477 119.69487,141.95608 C116.899865,133.938362 105.171362,111.043501 103.859129,111.043501 C100.420089,111.043501 101.508757,114.986149 109.1771,130.30227 C113.739327,139.414532 118.032086,147.448041 118.716515,148.15443 C120.694817,150.196115 120.172626,154.319657 117.358599,158.877992 C113.567467,165.019055 107.570942,183.721189 108.054206,187.896804 C108.804956,194.383204 112.436054,192.210274 113.355359,184.724515 C114.48376,175.535577 120.945556,159.641154 124.897459,156.333653 C127.109021,154.482778 128.268636,151.905536 128.573284,148.163978 C128.818001,145.157747 131.906711,135.560972 135.437115,126.837819 C138.96752,118.114666 141.511492,110.079835 141.090434,108.982574 C139.755727,105.504315 136.554941,106.824333 135.676765,111.215287 M174.714659,126.841564 C169.37392,129.699438 169.197653,130.049915 167.452978,141.283475 C165.577352,153.360398 165.225112,168.513913 166.548289,180.203784 L167.566817,189.202501 L161.346213,191.9541 C154.601949,194.937416 150.91195,200.302465 153.156708,203.861146 C155.104824,206.949562 157.09025,206.70198 157.571826,203.310532 C158.083734,199.706169 166.097413,193.204052 170.29418,192.987978 C172.116999,192.894116 173.522874,191.717021 173.97823,189.903529 C174.383277,188.290613 177.740353,184.944554 181.438431,182.467858 C188.546172,177.707551 194.317883,170.450278 194.317883,166.273341 C194.317883,162.684548 189.493165,158.361603 185.487795,158.361603 C180.701636,158.361603 180.027195,155.239403 183.731222,150.229385 C188.308065,144.038966 188.284856,130.867646 183.690534,127.147387 C179.896537,124.075276 179.885006,124.074836 174.714659,126.841564 M182.67318,134.240439 C184.752542,140.153164 174.808961,161.185104 171.588639,157.68562 C169.868715,155.81653 172.863122,135.012708 175.266374,132.134564 C177.872553,129.013319 181.163896,129.949075 182.67318,134.240439 M184.854262,162.269586 C190.589839,163.855621 189.673839,167.881335 181.645765,176.371155 C177.281618,180.986262 173.904933,183.573859 173.371946,182.711474 C172.876636,181.91012 172.127869,176.711937 171.707987,171.159972 L170.944531,161.065463 L176.209475,161.200234 C179.105172,161.274339 182.995308,161.755548 184.854262,162.269586 M132.642184,172.492256 C131.593837,175.224098 133.152917,177.288844 136.264027,177.288844 C139.014965,177.288844 139.431396,176.221769 138.067531,172.667568 C137.039234,169.987871 133.645289,169.878218 132.642184,172.492256 M203.781503,185.840798 C203.781503,187.657595 209.264724,193.512152 210.966361,193.512152 C212.534035,193.512152 211.991059,187.391138 210.270768,185.670847 C208.092403,183.492409 203.781503,183.605293 203.781503,185.840798" id="Fill-6" fill="#427B8A" fill-rule="nonzero"></path>
16
+ </g>
17
+ </g>
18
+ </g>
19
+ </svg>
data/renovate.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:base"
5
+ ]
6
+ }
data/syncem.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # (The MIT License)
4
4
  #
5
- # Copyright (c) 2018-2019 Yegor Bugayenko
5
+ # Copyright (c) 2018-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.specification_version = 2 if s.respond_to? :specification_version=
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 = 'syncem'
34
- s.version = '0.1.1'
30
+ s.version = '0.2.0'
35
31
  s.license = 'MIT'
36
32
  s.summary = 'Thread-safe decorator of Ruby objects'
37
33
  s.description = 'Sometimes you have an object that is not thread-safe,
@@ -44,13 +40,7 @@ decorate them with SyncEm decorator and that is it.'
44
40
  s.email = 'yegor256@gmail.com'
45
41
  s.homepage = 'http://github.com/yegor256/syncem'
46
42
  s.files = `git ls-files`.split($RS)
47
- s.test_files = s.files.grep(%r{^(test)/})
48
43
  s.rdoc_options = ['--charset=UTF-8']
49
44
  s.extra_rdoc_files = ['README.md']
50
- s.add_development_dependency 'minitest', '5.11.3'
51
- s.add_development_dependency 'rake', '12.3.1'
52
- s.add_development_dependency 'rdoc', '4.3.0'
53
- s.add_development_dependency 'rubocop', '0.62.0'
54
- s.add_development_dependency 'rubocop-rspec', '1.31.0'
55
- s.add_development_dependency 'threads', '0.3.0'
45
+ s.metadata['rubygems_mfa_required'] = 'true'
56
46
  end
data/test/test_syncem.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # (The MIT License)
4
4
  #
5
- # Copyright (c) 2018-2019 Yegor Bugayenko
5
+ # Copyright (c) 2018-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/syncem'
28
28
 
29
29
  # Syncem test.
30
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
- # Copyright:: Copyright (c) 2018-2019 Yegor Bugayenko
31
+ # Copyright:: Copyright (c) 2018-2023 Yegor Bugayenko
32
32
  # License:: MIT
33
33
  class SyncEmTest < Minitest::Test
34
34
  class Account
@@ -37,12 +37,12 @@ class SyncEmTest < Minitest::Test
37
37
  end
38
38
 
39
39
  def balance
40
- File.exist?(@file) ? IO.read(@file).to_i : 0
40
+ File.exist?(@file) ? File.read(@file).to_i : 0
41
41
  end
42
42
 
43
43
  def add(amount)
44
- now = File.exist?(@file) ? IO.read(@file).to_i : 0
45
- IO.write(@file, (now + amount).to_s)
44
+ now = File.exist?(@file) ? File.read(@file).to_i : 0
45
+ File.write(@file, (now + amount).to_s)
46
46
  end
47
47
 
48
48
  def read
@@ -71,6 +71,37 @@ class SyncEmTest < Minitest::Test
71
71
  end
72
72
  end
73
73
 
74
+ def test_works_with_send_method
75
+ obj = Object.new
76
+ def obj.send(_first, second)
77
+ second
78
+ end
79
+ synced = SyncEm.new(obj)
80
+ assert_equal(3, synced.send(2, 3))
81
+ assert_equal({ y: 2 }, synced.send({ x: 1 }, { y: 2 }))
82
+ end
83
+
84
+ def test_works_with_optional_arguments
85
+ obj = Object.new
86
+ def obj.foo(first, _second, ext1: 'a', ext2: 'b')
87
+ first + ext1 + ext2
88
+ end
89
+ synced = SyncEm.new(obj)
90
+ assert_equal('.xy', synced.foo('.', {}, ext1: 'x', ext2: 'y'))
91
+ assert_equal('fzb', synced.foo('f', {}, ext1: 'z'))
92
+ assert_equal('-ab', synced.foo('-', {}))
93
+ end
94
+
95
+ def test_works_with_default_value
96
+ obj = Object.new
97
+ def obj.foo(first, second = 42)
98
+ first + second
99
+ end
100
+ synced = SyncEm.new(obj)
101
+ assert_equal(15, synced.foo(7, 8))
102
+ assert_equal(43, synced.foo(1))
103
+ end
104
+
74
105
  def test_works_with_block
75
106
  Dir.mktmpdir do |dir|
76
107
  path = File.join(dir, 'f.txt')
metadata CHANGED
@@ -1,99 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syncem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.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: 2019-04-13 00:00:00.000000000 Z
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
83
- - !ruby/object:Gem::Dependency
84
- name: threads
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '='
88
- - !ruby/object:Gem::Version
89
- version: 0.3.0
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '='
95
- - !ruby/object:Gem::Version
96
- version: 0.3.0
11
+ date: 2023-11-13 00:00:00.000000000 Z
12
+ dependencies: []
97
13
  description: |-
98
14
  Sometimes you have an object that is not thread-safe,
99
15
  but you need to make sure each of its methods is thread-safe, because they
@@ -108,22 +24,28 @@ extra_rdoc_files:
108
24
  - README.md
109
25
  files:
110
26
  - ".0pdd.yml"
27
+ - ".github/workflows/codecov.yml"
28
+ - ".github/workflows/pdd.yml"
29
+ - ".github/workflows/rake.yml"
30
+ - ".github/workflows/xcop.yml"
111
31
  - ".gitignore"
112
32
  - ".pdd"
113
33
  - ".rubocop.yml"
114
34
  - ".rultor.yml"
115
- - ".travis.yml"
116
35
  - Gemfile
36
+ - LICENSE.txt
117
37
  - README.md
118
38
  - Rakefile
119
- - appveyor.yml
120
39
  - lib/syncem.rb
40
+ - logo.svg
41
+ - renovate.json
121
42
  - syncem.gemspec
122
43
  - test/test_syncem.rb
123
44
  homepage: http://github.com/yegor256/syncem
124
45
  licenses:
125
46
  - MIT
126
- metadata: {}
47
+ metadata:
48
+ rubygems_mfa_required: 'true'
127
49
  post_install_message:
128
50
  rdoc_options:
129
51
  - "--charset=UTF-8"
@@ -140,9 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
62
  - !ruby/object:Gem::Version
141
63
  version: '0'
142
64
  requirements: []
143
- rubygems_version: 3.0.1
65
+ rubygems_version: 3.4.10
144
66
  signing_key:
145
- specification_version: 2
67
+ specification_version: 4
146
68
  summary: Thread-safe decorator of Ruby objects
147
- test_files:
148
- - test/test_syncem.rb
69
+ test_files: []
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.6.0
4
- branches:
5
- only:
6
- - master
7
- install:
8
- - bundle install
9
- script:
10
- - set -e
11
- - rake
12
-
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