atomic_counter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f2a4121c78f51f3f68770e6da7a567e0e71195fe6e6e97e248967107ea1fbc36
4
+ data.tar.gz: 7f1a0cfe3423cc9b4ca8bbd811b058f89140563466d450cd30553bb47225e755
5
+ SHA512:
6
+ metadata.gz: 5ba418325c04ff717fd4b45eb46c7a0a9737bfc9027da06146b8f221a858581a463e866629c904be447e7a40691e7e22a43021a31cdf2ab5e17a74d261ef6cd9
7
+ data.tar.gz: d6bdd55911a06981a3b5460c369148a17099def8c3d43867c42916de124a8fd53bc6fbf609dd4856f14be4a2a385f7ed6ad8eb79a37d512e0f6f660c2bddc107
@@ -0,0 +1,67 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.5
6
+ working_directory: ~/repo
7
+
8
+ environment:
9
+ COVERAGE: true
10
+ CC_TEST_REPORTER_ID: 166bdd7eb4141a8d217becb77dc12146c254273ac24a65aa2752a3b195e33503
11
+
12
+ steps:
13
+ - checkout
14
+
15
+ - restore_cache:
16
+ keys:
17
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
18
+ # fallback to using the latest cache if no exact match is found
19
+ - v1-dependencies-
20
+
21
+ - run:
22
+ name: install dependencies
23
+ command: |
24
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
25
+
26
+ - save_cache:
27
+ paths:
28
+ - ./vendor/bundle
29
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
30
+
31
+ - run:
32
+ name: Setup Code Climate test-reporter
33
+ command: |
34
+ # download test reporter as a static binary
35
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
36
+ chmod +x ./cc-test-reporter
37
+
38
+ - run:
39
+ name: Code Climate before-build
40
+ command: |
41
+ ./cc-test-reporter before-build
42
+
43
+ # run tests!
44
+ - run:
45
+ name: run tests
46
+ command: |
47
+ mkdir /tmp/test-results
48
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
49
+ circleci tests split --split-by=timings)"
50
+
51
+ bundle exec rspec \
52
+ --format progress \
53
+ --out /tmp/test-results/rspec.xml \
54
+ --format progress \
55
+ $TEST_FILES
56
+
57
+ - run:
58
+ name: Report code coverage to Code Climate
59
+ command: |
60
+ ./cc-test-reporter after-build -t simplecov --exit-code $?
61
+
62
+ # collect reports
63
+ - store_test_results:
64
+ path: /tmp/test-results
65
+ - store_artifacts:
66
+ path: /tmp/test-results
67
+ destination: test-results
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,4 @@
1
+ 0.1.0
2
+ -----------
3
+
4
+ - Initial release!
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem "standard", group: [:development, :test]
5
+ gem "simplecov", group: [:test]
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ atomic_counter (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ docile (1.3.2)
12
+ jaro_winkler (1.5.3)
13
+ json (2.2.0)
14
+ parallel (1.18.0)
15
+ parser (2.6.5.0)
16
+ ast (~> 2.4.0)
17
+ rainbow (3.0.0)
18
+ rake (10.5.0)
19
+ rspec (3.8.0)
20
+ rspec-core (~> 3.8.0)
21
+ rspec-expectations (~> 3.8.0)
22
+ rspec-mocks (~> 3.8.0)
23
+ rspec-core (3.8.2)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-expectations (3.8.6)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-mocks (3.8.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-support (3.8.3)
32
+ rubocop (0.72.0)
33
+ jaro_winkler (~> 1.5.1)
34
+ parallel (~> 1.10)
35
+ parser (>= 2.6)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 1.7)
39
+ rubocop-performance (1.4.1)
40
+ rubocop (>= 0.71.0)
41
+ ruby-progressbar (1.10.1)
42
+ simplecov (0.17.1)
43
+ docile (~> 1.1)
44
+ json (>= 1.8, < 3)
45
+ simplecov-html (~> 0.10.0)
46
+ simplecov-html (0.10.2)
47
+ standard (0.1.4)
48
+ rubocop (~> 0.72.0)
49
+ rubocop-performance (~> 1.4.0)
50
+ unicode-display_width (1.6.0)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ atomic_counter!
57
+ bundler (~> 1.17)
58
+ rake (~> 10.0)
59
+ rspec (~> 3.0)
60
+ simplecov
61
+ standard
62
+
63
+ BUNDLED WITH
64
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Tero Tasanen
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 in
13
+ 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 NONINFRINGEMENT. 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
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ [![CircleCI](https://circleci.com/gh/ttasanen/atomic_counter/tree/master.svg?style=svg)](https://circleci.com/gh/ttasanen/atomic_counter/tree/master) [![Maintainability](https://api.codeclimate.com/v1/badges/7209351f288599145f32/maintainability)](https://codeclimate.com/github/ttasanen/atomic_counter/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/7209351f288599145f32/test_coverage)](https://codeclimate.com/github/ttasanen/atomic_counter/test_coverage)
2
+
3
+
4
+ # AtomicCounter
5
+
6
+ A simple thread safe counter for Ruby.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'atomic_counter'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install atomic_counter
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ counter = AtomicCounter.new
28
+ counter.increment
29
+
30
+ puts counter.reset # => 1
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ttasanen/atomic_counter.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "standard/rake"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "atomic_counter/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "atomic_counter"
7
+ spec.version = AtomicCounter::VERSION
8
+ spec.authors = ["Tero Tasanen"]
9
+ spec.email = ["tero.tasanen@gmail.com"]
10
+ spec.summary = "Atomic Counter for Ruby"
11
+ spec.description = "Thread safe Counter for Ruby"
12
+ spec.homepage = "https://github.com/ttasanen/atomic_counter"
13
+ spec.license = "MIT"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/ttasanen/atomic_counter"
20
+ spec.metadata["changelog_uri"] = "https://github.com/ttasanen/blob/master/Changes.md"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+ spec.add_development_dependency "bundler", "~> 1.17"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "atomic_counter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require "atomic_counter/version"
2
+ require "atomic_counter/counter"
3
+
4
+ module AtomicCounter
5
+ def self.new(start = 0)
6
+ AtomicCounter::Counter.new(start)
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ module AtomicCounter
2
+ class Counter
3
+ attr_reader :current
4
+
5
+ def initialize(start = 0)
6
+ @current = start
7
+ @initial = start
8
+ @mutex = Mutex.new
9
+ end
10
+
11
+ def increment(by = 1)
12
+ @mutex.synchronize do
13
+ @current += by
14
+ end
15
+ end
16
+
17
+ def decrement(by = 1)
18
+ @mutex.synchronize do
19
+ @current -= by
20
+ end
21
+ end
22
+
23
+ def reset
24
+ @mutex.synchronize do
25
+ local_value = @current
26
+ @current = @initial
27
+ local_value
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module AtomicCounter
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atomic_counter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tero Tasanen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '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: '3.0'
55
+ description: Thread safe Counter for Ruby
56
+ email:
57
+ - tero.tasanen@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".circleci/config.yml"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Changes.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - atomic_counter.gemspec
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/atomic_counter.rb
75
+ - lib/atomic_counter/counter.rb
76
+ - lib/atomic_counter/version.rb
77
+ homepage: https://github.com/ttasanen/atomic_counter
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ homepage_uri: https://github.com/ttasanen/atomic_counter
82
+ source_code_uri: https://github.com/ttasanen/atomic_counter
83
+ changelog_uri: https://github.com/ttasanen/blob/master/Changes.md
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.0.6
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Atomic Counter for Ruby
103
+ test_files: []