filequeue 0.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -2
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.ci +8 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +9 -3
- data/Rakefile +2 -19
- data/VERSION +1 -1
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/filequeue.gemspec +21 -45
- data/lib/filequeue.rb +39 -14
- data/lib/filequeue/version.rb +3 -0
- metadata +85 -59
- data/file_queue.rb +0 -52
- data/pkg/filequeue-0.0.2.gem +0 -0
- data/spec/filequeue_spec.rb +0 -96
- data/spec/spec_helper.rb +0 -4
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3bda8a00a34e6b94e1bf22199e00f0d9cf2c6d60
|
4
|
+
data.tar.gz: 3dd04b0390120f9d3891c91cac7712be948ff79d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3352418e0db83c98cff93e94ab161b4665c23629b851fd4909d6d445ba03dbac93ca33f706cff02218c82e7bcd02d46970fb17da93c1ac68035bb19d5c28fcd2
|
7
|
+
data.tar.gz: f52b0790ba5dc1212465a3891e27d76d52541f98d213bb250c459338f3ce650a63820aa858e951e25563073ebee1f9cb139858fd34ff3efa82cc474b6c91b382
|
data/.gitignore
ADDED
data/.rspec
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at pezra@barelyenough.org. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.ci
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
filequeue (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.4.2)
|
11
|
+
rspec (3.4.0)
|
12
|
+
rspec-core (~> 3.4.0)
|
13
|
+
rspec-expectations (~> 3.4.0)
|
14
|
+
rspec-mocks (~> 3.4.0)
|
15
|
+
rspec-core (3.4.1)
|
16
|
+
rspec-support (~> 3.4.0)
|
17
|
+
rspec-expectations (3.4.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.4.0)
|
20
|
+
rspec-mocks (3.4.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.4.0)
|
23
|
+
rspec-support (3.4.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
filequeue!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Peter Williams
|
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.
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
|
2
|
+
|
3
|
+
## FileQueue [![Build Status](https://travis-ci.org/pezra/filequeue.svg)](https://travis-ci.org/pezra/filequeue)
|
4
|
+
...is a simple file based queue written in Ruby that uses the Ruby `File` class in standard library to push and pop items into a queue. It's not web scale but is nice for lightweight async queuing apps.
|
3
5
|
|
4
6
|
Originally written by [daddz](http://www.github.com/daddz) and found in [this gist](https://gist.github.com/352509). Thanks, daddz!
|
5
7
|
|
@@ -17,4 +19,8 @@ Originally written by [daddz](http://www.github.com/daddz) and found in [this gi
|
|
17
19
|
queue.pop
|
18
20
|
=> "an item"
|
19
21
|
|
20
|
-
See `spec/filequeue_spec.rb` for more usage details
|
22
|
+
See `spec/filequeue_spec.rb` for more usage details
|
23
|
+
|
24
|
+
## Continuous Integration
|
25
|
+
|
26
|
+
[![Build Status](http://travis-ci.org/maxogden/filequeue.png)](http://travis-ci.org/maxogden/filequeue)
|
data/Rakefile
CHANGED
@@ -1,23 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
3
|
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "filequeue"
|
8
|
-
gem.summary = %Q{A simple file based queue in Ruby}
|
9
|
-
gem.description = %Q{A simple file based queue in Ruby}
|
10
|
-
gem.email = "max@maxogden.com"
|
11
|
-
gem.homepage = "http://github.com/maxogden/filequeue"
|
12
|
-
gem.authors = ["Max Ogden", "daddz"]
|
13
|
-
end
|
14
|
-
Jeweler::GemcutterTasks.new
|
15
|
-
rescue LoadError
|
16
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
17
|
-
end
|
18
|
-
|
19
|
-
require 'rspec/core/rake_task'
|
20
4
|
RSpec::Core::RakeTask.new(:spec)
|
21
5
|
|
22
6
|
task :default => :spec
|
23
|
-
task :test => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.0.2
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "filequeue"
|
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__)
|
data/bin/setup
ADDED
data/filequeue.gemspec
CHANGED
@@ -1,51 +1,27 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
1
|
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "filequeue/version"
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.md"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".gemtest",
|
21
|
-
".rspec",
|
22
|
-
"LICENSE",
|
23
|
-
"README.md",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"file_queue.rb",
|
27
|
-
"filequeue.gemspec",
|
28
|
-
"lib/filequeue.rb",
|
29
|
-
"pkg/filequeue-0.0.2.gem",
|
30
|
-
"spec/filequeue_spec.rb",
|
31
|
-
"spec/spec_helper.rb"
|
32
|
-
]
|
33
|
-
s.homepage = %q{http://github.com/maxogden/filequeue}
|
34
|
-
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = %q{1.4.2}
|
36
|
-
s.summary = %q{A simple file based queue in Ruby}
|
37
|
-
s.test_files = [
|
38
|
-
"spec/filequeue_spec.rb",
|
39
|
-
"spec/spec_helper.rb"
|
40
|
-
]
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "filequeue"
|
8
|
+
spec.version = Filequeue::VERSION
|
9
|
+
spec.authors = ["Peter Williams", "Max Ogden", "daddz"]
|
10
|
+
spec.email = ["pezra@barelyenough.org"]
|
41
11
|
|
42
|
-
|
43
|
-
|
12
|
+
spec.summary = "Simple file based queue"
|
13
|
+
spec.description = "File based queue for coordinating multiple processes."
|
14
|
+
spec.homepage = "https://github.com/pezra/filequeue"
|
15
|
+
spec.license = "MIT"
|
44
16
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
else
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
49
19
|
end
|
50
|
-
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
51
23
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
data/lib/filequeue.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
1
3
|
class FileQueue
|
2
|
-
|
3
|
-
|
4
|
-
def initialize(file_name, delimiter="\n")
|
4
|
+
attr_accessor :file_name, :delimiter, :lock_timeout
|
5
|
+
|
6
|
+
def initialize(file_name, delimiter="\n", lock_timeout: 10)
|
5
7
|
@delimiter = delimiter
|
6
8
|
@file_name = file_name
|
9
|
+
@lock_timeout = lock_timeout
|
7
10
|
end
|
8
11
|
|
9
12
|
def push(obj)
|
@@ -16,22 +19,24 @@ class FileQueue
|
|
16
19
|
end
|
17
20
|
|
18
21
|
alias << push
|
19
|
-
|
22
|
+
|
20
23
|
def pop
|
21
24
|
value = nil
|
22
|
-
|
23
|
-
safe_open 'r' do |file|
|
25
|
+
safe_open 'r+' do |file|
|
24
26
|
value = file.gets @delimiter
|
25
27
|
rest = file.read
|
26
|
-
|
27
|
-
|
28
|
-
file.write
|
28
|
+
file.rewind
|
29
|
+
file.truncate(0)
|
30
|
+
file.write(rest)
|
29
31
|
end
|
30
32
|
value ? value[0..-(@delimiter.length) - 1] : nil
|
31
33
|
end
|
32
34
|
|
33
35
|
def length
|
34
36
|
count = 0
|
37
|
+
unless(File.exist?(@file_name))
|
38
|
+
return 0
|
39
|
+
end
|
35
40
|
safe_open 'r' do |file|
|
36
41
|
count = file.read.count @delimiter
|
37
42
|
end
|
@@ -45,13 +50,33 @@ class FileQueue
|
|
45
50
|
def clear
|
46
51
|
safe_open 'w' do |file| end
|
47
52
|
end
|
48
|
-
|
49
|
-
|
53
|
+
|
54
|
+
protected
|
55
|
+
|
50
56
|
def safe_open(mode)
|
51
57
|
File.open(@file_name, mode) do |file|
|
52
|
-
file
|
58
|
+
lock file
|
53
59
|
yield file
|
54
|
-
file.flock File::LOCK_UN
|
55
60
|
end
|
56
61
|
end
|
57
|
-
|
62
|
+
|
63
|
+
DELAY_RANGE = (0..0.01).freeze
|
64
|
+
|
65
|
+
# Locks the queue file for exclusive access. This will gives up
|
66
|
+
# after `lock_timeout` seconds.
|
67
|
+
#
|
68
|
+
# Raises `FileLockError` if unable to acquire a lock.
|
69
|
+
#
|
70
|
+
# Return is undefined.
|
71
|
+
def lock(file)
|
72
|
+
deadline = (Time.now + lock_timeout)
|
73
|
+
|
74
|
+
until Time.now >= deadline || lock_acquired = file.flock(File::LOCK_NB|File::LOCK_EX)
|
75
|
+
sleep(rand(DELAY_RANGE))
|
76
|
+
end
|
77
|
+
|
78
|
+
(raise FileLockError, "Queue file appears to be permanently locked") unless lock_acquired
|
79
|
+
end
|
80
|
+
|
81
|
+
FileLockError = Class.new(Timeout::Error)
|
82
|
+
end
|
metadata
CHANGED
@@ -1,81 +1,107 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: filequeue
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.3
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
7
|
+
- Peter Williams
|
13
8
|
- Max Ogden
|
14
9
|
- daddz
|
15
10
|
autorequire:
|
16
|
-
bindir:
|
11
|
+
bindir: exe
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
13
|
+
date: 2018-07-31 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.16'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.16'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '10.0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '10.0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rspec
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '3.0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '3.0'
|
57
|
+
description: File based queue for coordinating multiple processes.
|
58
|
+
email:
|
59
|
+
- pezra@barelyenough.org
|
25
60
|
executables: []
|
26
|
-
|
27
61
|
extensions: []
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
|
33
|
-
- .
|
34
|
-
- .
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gemtest"
|
65
|
+
- ".gitignore"
|
66
|
+
- ".rspec"
|
67
|
+
- ".ruby-version"
|
68
|
+
- ".travis.yml"
|
69
|
+
- CODE_OF_CONDUCT.md
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.ci
|
72
|
+
- Gemfile.lock
|
35
73
|
- LICENSE
|
74
|
+
- LICENSE.txt
|
36
75
|
- README.md
|
37
76
|
- Rakefile
|
38
77
|
- VERSION
|
39
|
-
-
|
78
|
+
- bin/console
|
79
|
+
- bin/setup
|
40
80
|
- filequeue.gemspec
|
41
81
|
- lib/filequeue.rb
|
42
|
-
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
licenses: []
|
48
|
-
|
82
|
+
- lib/filequeue/version.rb
|
83
|
+
homepage: https://github.com/pezra/filequeue
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
49
87
|
post_install_message:
|
50
88
|
rdoc_options: []
|
51
|
-
|
52
|
-
require_paths:
|
89
|
+
require_paths:
|
53
90
|
- lib
|
54
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
-
|
56
|
-
requirements:
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
57
93
|
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
version: "0"
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
|
-
requirements:
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
66
98
|
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
segments:
|
70
|
-
- 0
|
71
|
-
version: "0"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
72
101
|
requirements: []
|
73
|
-
|
74
102
|
rubyforge_project:
|
75
|
-
rubygems_version:
|
103
|
+
rubygems_version: 2.6.13
|
76
104
|
signing_key:
|
77
|
-
specification_version:
|
78
|
-
summary:
|
79
|
-
test_files:
|
80
|
-
- spec/filequeue_spec.rb
|
81
|
-
- spec/spec_helper.rb
|
105
|
+
specification_version: 4
|
106
|
+
summary: Simple file based queue
|
107
|
+
test_files: []
|
data/file_queue.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
class FileQueue
|
2
|
-
|
3
|
-
def initialize(file_name)
|
4
|
-
@file_name = file_name
|
5
|
-
end
|
6
|
-
|
7
|
-
def push(obj)
|
8
|
-
safe_open('a') do |file|
|
9
|
-
file.write(obj + "\n")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
alias << push
|
14
|
-
|
15
|
-
def pop
|
16
|
-
value = nil
|
17
|
-
rest = nil
|
18
|
-
safe_open('r') do |file|
|
19
|
-
value = file.gets
|
20
|
-
rest = file.read
|
21
|
-
end
|
22
|
-
safe_open('w+') do |file|
|
23
|
-
file.write(rest)
|
24
|
-
end
|
25
|
-
value
|
26
|
-
end
|
27
|
-
|
28
|
-
def length
|
29
|
-
count = 0
|
30
|
-
safe_open('r') do |file|
|
31
|
-
count = file.read.count("\n")
|
32
|
-
end
|
33
|
-
count
|
34
|
-
end
|
35
|
-
|
36
|
-
def empty?
|
37
|
-
return length == 0
|
38
|
-
end
|
39
|
-
|
40
|
-
def clear
|
41
|
-
safe_open('w') do |file| end
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
def safe_open(mode)
|
46
|
-
File.open(@file_name, mode) do |file|
|
47
|
-
file.flock(File::LOCK_EX)
|
48
|
-
yield file
|
49
|
-
file.flock(File::LOCK_UN)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/pkg/filequeue-0.0.2.gem
DELETED
Binary file
|
data/spec/filequeue_spec.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
test_file = "pizza.waffle"
|
4
|
-
|
5
|
-
describe FileQueue do
|
6
|
-
subject do
|
7
|
-
FileQueue.new test_file
|
8
|
-
end
|
9
|
-
|
10
|
-
after :each do
|
11
|
-
File.open(test_file, 'w') {|file| file.truncate 0 }
|
12
|
-
end
|
13
|
-
|
14
|
-
after :all do
|
15
|
-
File.delete test_file
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#initialize' do
|
19
|
-
it 'should have a file name and default delimiter' do
|
20
|
-
subject.file_name.should == test_file
|
21
|
-
subject.delimiter.should == "\n"
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should let you specify your own queue delimiter' do
|
25
|
-
FileQueue.new(test_file, ",").delimiter.should == ","
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#push' do
|
30
|
-
it 'should add an entry to the queue' do
|
31
|
-
subject.push "bacon"
|
32
|
-
File.open(test_file, 'r').read.should == "bacon\n"
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should add multiple entries to the queue' do
|
36
|
-
subject.push "cats"
|
37
|
-
subject.push "are awesome"
|
38
|
-
File.open(test_file, 'r').read.should == "cats\nare awesome\n"
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should use the delimiter to separate entries in the queue' do
|
42
|
-
FileQueue.new(test_file, ",").push "jello"
|
43
|
-
File.open(test_file, 'r').read.should == "jello,"
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should raise if your object contains the delimiter' do
|
47
|
-
lambda { subject.push "yee\nhaw" }.should raise_error(StandardError, "Queue objects cannot contain the queue delimiter")
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should let you use the << syntax to add things to the queue' do
|
51
|
-
subject << "angle brackets!"
|
52
|
-
subject.pop.should == "angle brackets!"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#pop' do
|
57
|
-
it 'should retrieve an item from the queue' do
|
58
|
-
subject.push "important document"
|
59
|
-
subject.pop.should == "important document"
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should return the oldest item in the queue' do
|
63
|
-
subject.push "old thing"
|
64
|
-
subject.push "new thing"
|
65
|
-
subject.pop.should == "old thing"
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should return nil if the queue is empty' do
|
69
|
-
subject.pop.should be_nil
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe '#length' do
|
74
|
-
it 'should tell you the size of the queue' do
|
75
|
-
subject.length.should == 0
|
76
|
-
subject.push "content"
|
77
|
-
subject.length.should == 1
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe '#empty' do
|
82
|
-
it 'should tell you if the queue is empty or not' do
|
83
|
-
subject.empty?.should be_true
|
84
|
-
subject.push "content"
|
85
|
-
subject.empty?.should be_false
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe '#clear' do
|
90
|
-
it 'should empty the queue' do
|
91
|
-
subject.push "content"
|
92
|
-
subject.clear
|
93
|
-
subject.empty?.should be_true
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
data/spec/spec_helper.rb
DELETED