trail 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +13 -0
- data/README.rdoc +41 -0
- data/Rakefile +2 -0
- data/lib/trail.rb +33 -0
- data/lib/trail/version.rb +3 -0
- data/test/trail_test.rb +50 -0
- data/trail.gemspec +20 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2011 Maurycy Pawlowski-Wieronski <maurycy@g.pl>
|
2
|
+
|
3
|
+
Permission to use, copy, modify, and distribute this software for any
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
=Trail
|
2
|
+
|
3
|
+
Trail is a lightweight queue for delayed and normalized execution.
|
4
|
+
|
5
|
+
==Quick Start
|
6
|
+
|
7
|
+
First, create a trail:
|
8
|
+
|
9
|
+
t = Trail.new
|
10
|
+
|
11
|
+
Then, define the normalization method:
|
12
|
+
|
13
|
+
t.normalize = lambda do |trail|
|
14
|
+
trail.uniq
|
15
|
+
end
|
16
|
+
|
17
|
+
And, the commit method:
|
18
|
+
|
19
|
+
t.commit = lambda do |trail|
|
20
|
+
trail.each {|e| puts e }
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
Push some data:
|
25
|
+
|
26
|
+
100.times { t.push("hello, world") }
|
27
|
+
|
28
|
+
And, commit the trail:
|
29
|
+
|
30
|
+
t.commit!
|
31
|
+
|
32
|
+
Please note that Trail#commit! returns Trail#commit return.
|
33
|
+
|
34
|
+
It is possible to specify the watch method:
|
35
|
+
|
36
|
+
t.watch = lambda do |trail, v|
|
37
|
+
puts 'hello'
|
38
|
+
trail
|
39
|
+
end
|
40
|
+
|
41
|
+
Please note that Trail#watch return overwrites the trail's queue.
|
data/Rakefile
ADDED
data/lib/trail.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Trail
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@queue = []
|
5
|
+
|
6
|
+
@watch = nil
|
7
|
+
@commit = nil
|
8
|
+
@normalize = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def normalize=(v)
|
12
|
+
@normalize = v
|
13
|
+
end
|
14
|
+
|
15
|
+
def commit=(v)
|
16
|
+
@commit = v
|
17
|
+
end
|
18
|
+
|
19
|
+
def watch=(v)
|
20
|
+
@watch = v
|
21
|
+
end
|
22
|
+
|
23
|
+
def push(v)
|
24
|
+
@queue.push(v)
|
25
|
+
@queue = @watch.call(v) unless @watch.nil?
|
26
|
+
v
|
27
|
+
end
|
28
|
+
|
29
|
+
def commit!
|
30
|
+
@queue = @normalize.call(@queue) unless @normalize.nil?
|
31
|
+
@commit.nil? ? @queue : @commit.call(@queue)
|
32
|
+
end
|
33
|
+
end
|
data/test/trail_test.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'ruby-debug'
|
4
|
+
|
5
|
+
require '../lib/trail'
|
6
|
+
|
7
|
+
class TrailTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_new
|
13
|
+
assert_nothing_raised { Trail.new }
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_commit
|
17
|
+
t = Trail.new
|
18
|
+
t.commit = lambda do |trail|
|
19
|
+
'hello'
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_equal 'hello', t.commit!
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_normalize=
|
26
|
+
t = Trail.new
|
27
|
+
t.normalize = lambda do |trail|
|
28
|
+
[]
|
29
|
+
end
|
30
|
+
|
31
|
+
10.times do
|
32
|
+
t.push('hello')
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_equal [], t.commit!
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_watch=
|
39
|
+
t = Trail.new
|
40
|
+
t.watch = lambda do |trail|
|
41
|
+
['random']
|
42
|
+
end
|
43
|
+
|
44
|
+
10.times do
|
45
|
+
t.push('hello')
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_equal ['random'], t.commit!
|
49
|
+
end
|
50
|
+
end
|
data/trail.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "trail/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "trail"
|
7
|
+
s.version = Trail::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Maurycy Pawlowski-Wieronski"]
|
10
|
+
s.email = ["maurycy@g.pl"]
|
11
|
+
s.homepage = "https://github.com/maurycy/trail"
|
12
|
+
s.summary = %q{A lightweight queue for delayed and normalized execution}
|
13
|
+
|
14
|
+
s.rubyforge_project = "trail"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Maurycy Pawlowski-Wieronski
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-28 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email:
|
24
|
+
- maurycy@g.pl
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.rdoc
|
36
|
+
- Rakefile
|
37
|
+
- lib/trail.rb
|
38
|
+
- lib/trail/version.rb
|
39
|
+
- test/trail_test.rb
|
40
|
+
- trail.gemspec
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: https://github.com/maurycy/trail
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: trail
|
71
|
+
rubygems_version: 1.6.2
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: A lightweight queue for delayed and normalized execution
|
75
|
+
test_files:
|
76
|
+
- test/trail_test.rb
|