ring_buffer 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e07ec3f0bcf2339338a61268b3212cc5340d02bd
4
+ data.tar.gz: fa926215c7fe0b7806e1a50556fcd969f85f66b0
5
+ SHA512:
6
+ metadata.gz: 403669104df1ef321ed05462d59341fbccc215f4258f400ae5ea20d207b8d38d2621e38711b574fa41ee6fea018bf0f32255f7535e5e23f6b0d0124a340a0d81
7
+ data.tar.gz: e69f51c42c402b1a1b161365e65813b6022aa9ed1f19a8355e50fa8840bb8e313550daad17c85a70925711bc0a04abc98b716377b2f5acd6202754febefa8b4e
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_PATH: "./vendor/.bundle"
3
+ BUNDLE_DISABLE_SHARED_GEMS: "true"
@@ -0,0 +1,11 @@
1
+ /vendor/.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,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.3.5
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ring_buffer.gemspec
6
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ring_buffer (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (0.9.0)
12
+ pry (0.11.1)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.9.0)
15
+ rake (12.1.0)
16
+ rspec (3.6.0)
17
+ rspec-core (~> 3.6.0)
18
+ rspec-expectations (~> 3.6.0)
19
+ rspec-mocks (~> 3.6.0)
20
+ rspec-core (3.6.0)
21
+ rspec-support (~> 3.6.0)
22
+ rspec-expectations (3.6.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.6.0)
25
+ rspec-mocks (3.6.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.6.0)
28
+ rspec-support (3.6.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.15)
35
+ pry
36
+ rake (~> 12.1)
37
+ ring_buffer!
38
+ rspec (~> 3.6)
39
+
40
+ BUNDLED WITH
41
+ 1.15.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 TODO: Write your name
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,68 @@
1
+ # ring_buffer
2
+
3
+ ring_buffer provides a simple ring buffer implementation in Ruby. A ring buffer
4
+ is a queue with a maximum capacity. When the capacity exceeds, the first
5
+ element inserted is removed.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ring_buffer'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ring_buffer
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ buffer = RingBuffer.new 2
27
+ buffer << 'first element'
28
+ buffer << 'second element'
29
+ buffer << 'third element'
30
+ p buffer
31
+ # ['second element', 'third element']
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repository, run `bin/setup` to install dependencies.
37
+ Then, run `rake spec` to run the tests. You can also run `bin/console` for an
38
+ interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To
41
+ release a new version, update the version number in `version.rb`, and then run
42
+ `bundle exec rake release`, which will create a git tag for the version, push
43
+ git commits and tags, and push the `.gem` file to
44
+ [rubygems.org](https://rubygems.org).
45
+
46
+ ### Without installing Ruby globally
47
+
48
+ On my work station, I prefer to use a Docker image with Ruby installed instead
49
+ of installing Ruby locally. Hence, any `bundle …` command can be prefixed with
50
+ `docker-compose run ring-buffer`. For instance, running the tests is done with
51
+ the command `docker-compose run ring-buffer bundle exec rake spec`.
52
+
53
+ ## Acknowledgment
54
+
55
+ This gem is a generalization of the wonderful work from
56
+ [Nimster](https://github.com/Nimster/) and its
57
+ [`ringbuffer`](https://gist.github.com/Nimster/4078106#file-ringbuffer-rb)
58
+ gist.
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at
63
+ https://github.com/EtienneM/proc_parser.
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT
68
+ License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ring_buffer"
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,12 @@
1
+ version: '2'
2
+ services:
3
+ ring-buffer:
4
+ image: ruby:2.3
5
+ environment:
6
+ BUNDLE_BIN: "/usr/src/app/vendor/.bundle/ruby/2.3.0/bin"
7
+ BUNDLE_PATH: "/usr/src/app/vendor/.bundle/ruby/2.3.0"
8
+ BUNDLE_APP_CONFIG: "/usr/src/app/.bundle"
9
+ working_dir: /usr/src/app
10
+ volumes:
11
+ - ./:/usr/src/app/
12
+ command: "true"
@@ -0,0 +1,22 @@
1
+ require 'ring_buffer/version'
2
+
3
+ class RingBuffer < Array
4
+ attr_reader :max_size
5
+
6
+ alias :push :<<
7
+
8
+ def initialize(max_size)
9
+ raise 'max_size must be an integer' if !max_size.is_a? Integer
10
+ raise 'max_size must be positive' if max_size < 0
11
+
12
+ @max_size = max_size
13
+ end
14
+
15
+ def <<(element)
16
+ return super(element) if size < @max_size
17
+
18
+ # If the RingBuffer is full, remove the first element and add the new at the end.
19
+ shift
20
+ push element
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ class RingBuffer < Array
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'ring_buffer/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'ring_buffer'
9
+ spec.version = RingBuffer::VERSION
10
+ spec.authors = ['Étienne Michon']
11
+ spec.email = ['etienne@scalingo.com']
12
+
13
+ spec.summary = 'RingBuffer provides a simple ring buffer implementation in Ruby'
14
+ spec.description = 'RingBuffer provides a simple ring buffer implementation in Ruby. A ring
15
+ buffer is a queue with a maximum capacity. When the capacity exceeds, the
16
+ first element inserted is removed.'
17
+
18
+ spec.homepage = 'https://github.com/EtienneM/ring_buffer'
19
+ spec.license = 'MIT'
20
+
21
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
22
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
23
+ if spec.respond_to?(:metadata)
24
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
25
+ else
26
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
27
+ 'public gem pushes.'
28
+ end
29
+
30
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
31
+ f.match(%r{^(test|spec|features)/})
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+
37
+ spec.add_development_dependency 'bundler', '~> 1.15'
38
+ spec.add_development_dependency 'rake', '~> 12.1'
39
+ spec.add_development_dependency 'rspec', '~> 3.6'
40
+ spec.add_development_dependency 'pry'
41
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ring_buffer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Étienne Michon
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-09 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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.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.1'
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.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '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'
69
+ description: |-
70
+ RingBuffer provides a simple ring buffer implementation in Ruby. A ring
71
+ buffer is a queue with a maximum capacity. When the capacity exceeds, the
72
+ first element inserted is removed.
73
+ email:
74
+ - etienne@scalingo.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".bundle/config"
80
+ - ".gitignore"
81
+ - ".rspec"
82
+ - ".ruby-version"
83
+ - ".travis.yml"
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - LICENSE
87
+ - README.md
88
+ - Rakefile
89
+ - bin/console
90
+ - bin/setup
91
+ - docker-compose.yml
92
+ - lib/ring_buffer.rb
93
+ - lib/ring_buffer/version.rb
94
+ - ring_buffer.gemspec
95
+ homepage: https://github.com/EtienneM/ring_buffer
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ allowed_push_host: https://rubygems.org
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.5.2.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: RingBuffer provides a simple ring buffer implementation in Ruby
120
+ test_files: []