syncem 0.1.2 → 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: d6cc69151ea6e9cedcc556cc93381baff79fa64fb2678fa9ec11ea9be954a2f4
4
- data.tar.gz: ac322a4adb09be7f4dd7d9c4d2eaf19997d80c79ef0b2e37cc3a90e248bd62ea
3
+ metadata.gz: 717e4aacf4dedf530e9310ff99bc1093133b7ed37d852e671d1c0030cd8e05a9
4
+ data.tar.gz: '0329b04fc3a58177996e3d0a168cc64a71e9d288d95bda071fd4b80d5c8c5353'
5
5
  SHA512:
6
- metadata.gz: e041ddf121dfa41dc9392c5b0f6bb0a084e99c0d0fd03bd941587c7fec27a5545400feeb7ea4767270b319ce8acf744b4c94389db25f6b8843a073eda9841f46
7
- data.tar.gz: 6dcc736e27e91851de2f331c5d14d6c4fde92f7c8e156035c0fbb469f48a3ba9037ebb3f065876bf120a59166e9dddb22e13130a2574d3035c9dea373cdb9169
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,10 +1,13 @@
1
+ docker:
2
+ image: yegor256/rultor-image:1.22.0
1
3
  assets:
2
4
  rubygems.yml: yegor256/home#assets/rubygems.yml
3
- install: |-
4
- export GEM_HOME=~/.ruby
5
- export GEM_PATH=$GEM_HOME:$GEM_PATH
6
- bundle install
5
+ install: |
6
+ sudo gem install pdd
7
+ pdd -f /dev/null
8
+ sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
7
9
  release:
10
+ pre: false
8
11
  script: |-
9
12
  bundle exec rake
10
13
  rm -rf *.gem
@@ -16,9 +19,4 @@ release:
16
19
  gem push *.gem --config-file ../rubygems.yml
17
20
  merge:
18
21
  script: |-
19
- 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) 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/README.md CHANGED
@@ -4,15 +4,16 @@
4
4
  [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/syncem)](http://www.rultor.com/p/yegor256/syncem)
5
5
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
6
6
 
7
- [![Build Status](https://travis-ci.org/yegor256/syncem.svg)](https://travis-ci.org/yegor256/syncem)
8
- [![Build status](https://ci.appveyor.com/api/projects/status/m7hisfd90tpc198s?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)
9
8
  [![Gem Version](https://badge.fury.io/rb/syncem.svg)](http://badge.fury.io/rb/syncem)
10
9
  [![Maintainability](https://api.codeclimate.com/v1/badges/5528e182bb5e4a2ecc1f/maintainability)](https://codeclimate.com/github/yegor256/syncem/maintainability)
11
10
  [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/syncem/master/frames)
12
-
13
11
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/syncem)](https://hitsofcode.com/view/github/yegor256/syncem)
14
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/syncem/blob/master/LICENSE.txt)
15
13
 
14
+ Read this blog post:
15
+ [_SyncEm: Thread-Safe Decorators in Ruby_](https://www.yegor256.com/2019/06/26/syncem.html).
16
+
16
17
  Sometimes you have an object that is not thread-safe,
17
18
  but you need to make sure each of its methods is thread-safe, because they
18
19
  deal with some resources, like files or databases and you want them to
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,7 +29,7 @@
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
35
  undef_method :send
@@ -41,9 +41,18 @@ class SyncEm
41
41
 
42
42
  def method_missing(*args)
43
43
  @mutex.synchronize do
44
- if @origin.respond_to?(args[0])
45
- @origin.__send__(*args) do |*a|
46
- 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
47
56
  end
48
57
  else
49
58
  super
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.2'
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
@@ -73,11 +73,33 @@ class SyncEmTest < Minitest::Test
73
73
 
74
74
  def test_works_with_send_method
75
75
  obj = Object.new
76
- def obj.send(first, second)
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)
77
98
  first + second
78
99
  end
79
100
  synced = SyncEm.new(obj)
80
- assert_equal(5, synced.send(2, 3))
101
+ assert_equal(15, synced.foo(7, 8))
102
+ assert_equal(43, synced.foo(1))
81
103
  end
82
104
 
83
105
  def test_works_with_block
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.2
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-06-23 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,24 +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
117
36
  - LICENSE.txt
118
37
  - README.md
119
38
  - Rakefile
120
- - appveyor.yml
121
39
  - lib/syncem.rb
122
40
  - logo.svg
41
+ - renovate.json
123
42
  - syncem.gemspec
124
43
  - test/test_syncem.rb
125
44
  homepage: http://github.com/yegor256/syncem
126
45
  licenses:
127
46
  - MIT
128
- metadata: {}
47
+ metadata:
48
+ rubygems_mfa_required: 'true'
129
49
  post_install_message:
130
50
  rdoc_options:
131
51
  - "--charset=UTF-8"
@@ -142,9 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
62
  - !ruby/object:Gem::Version
143
63
  version: '0'
144
64
  requirements: []
145
- rubygems_version: 3.0.1
65
+ rubygems_version: 3.4.10
146
66
  signing_key:
147
- specification_version: 2
67
+ specification_version: 4
148
68
  summary: Thread-safe decorator of Ruby objects
149
- test_files:
150
- - 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
- - bundle exec 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