minuteman 1.0.3 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gems +3 -0
- data/.travis.yml +4 -3
- data/ORIGIN.md +21 -0
- data/README.md +115 -122
- data/Rakefile +3 -3
- data/SPEC.md +21 -0
- data/lib/minuteman.rb +88 -122
- data/lib/minuteman/analyzable.rb +96 -0
- data/lib/minuteman/analyzer.rb +21 -0
- data/lib/minuteman/configuration.rb +25 -0
- data/lib/minuteman/counter.rb +21 -0
- data/lib/minuteman/event.rb +12 -0
- data/lib/minuteman/lua/operations.lua +37 -0
- data/lib/minuteman/model.rb +36 -0
- data/lib/minuteman/result.rb +12 -0
- data/lib/minuteman/trigger.rb +4 -0
- data/lib/minuteman/user.rb +38 -0
- data/minuteman.gemspec +4 -5
- data/test/helper.rb +2 -0
- data/test/minuteman_bench.rb +72 -0
- data/test/minuteman_test.rb +204 -0
- metadata +44 -73
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -30
- data/lib/minuteman/bit_operations.rb +0 -97
- data/lib/minuteman/bit_operations/data.rb +0 -33
- data/lib/minuteman/bit_operations/operation.rb +0 -115
- data/lib/minuteman/bit_operations/plain.rb +0 -34
- data/lib/minuteman/bit_operations/result.rb +0 -15
- data/lib/minuteman/bit_operations/with_data.rb +0 -56
- data/lib/minuteman/keys_methods.rb +0 -23
- data/lib/minuteman/time_events.rb +0 -18
- data/lib/minuteman/time_span.rb +0 -36
- data/lib/minuteman/time_spans.rb +0 -7
- data/lib/minuteman/time_spans/day.rb +0 -17
- data/lib/minuteman/time_spans/hour.rb +0 -19
- data/lib/minuteman/time_spans/minute.rb +0 -19
- data/lib/minuteman/time_spans/month.rb +0 -17
- data/lib/minuteman/time_spans/week.rb +0 -18
- data/lib/minuteman/time_spans/year.rb +0 -17
- data/test/bench/minuteman_bench.rb +0 -37
- data/test/test_helper.rb +0 -9
- data/test/unit/minuteman_test.rb +0 -225
metadata
CHANGED
@@ -1,80 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minuteman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0.pre
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- elcuervo
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-10-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: redic
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 1.5.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 1.5.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: ohm
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
38
|
-
type: :
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 4.3.0
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: minitest-given
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 3.0.0
|
54
|
-
type: :development
|
33
|
+
version: 2.3.0
|
34
|
+
type: :runtime
|
55
35
|
prerelease: false
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
37
|
requirements:
|
59
|
-
- - ~>
|
38
|
+
- - "~>"
|
60
39
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.0
|
40
|
+
version: 2.3.0
|
62
41
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
42
|
+
name: cutest
|
64
43
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
44
|
requirements:
|
67
|
-
- - ~>
|
45
|
+
- - "~>"
|
68
46
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.2.
|
47
|
+
version: 1.2.2
|
70
48
|
type: :development
|
71
49
|
prerelease: false
|
72
50
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
51
|
requirements:
|
75
|
-
- - ~>
|
52
|
+
- - "~>"
|
76
53
|
- !ruby/object:Gem::Version
|
77
|
-
version: 1.2.
|
54
|
+
version: 1.2.2
|
78
55
|
description: Fast and furious tracking system using Redis bitwise operations
|
79
56
|
email:
|
80
57
|
- yo@brunoaguirre.com
|
@@ -82,61 +59,55 @@ executables: []
|
|
82
59
|
extensions: []
|
83
60
|
extra_rdoc_files: []
|
84
61
|
files:
|
85
|
-
- .
|
86
|
-
-
|
87
|
-
- Gemfile.lock
|
62
|
+
- ".gems"
|
63
|
+
- ".travis.yml"
|
88
64
|
- HUGS
|
89
65
|
- LICENSE
|
66
|
+
- ORIGIN.md
|
90
67
|
- README.md
|
91
68
|
- Rakefile
|
69
|
+
- SPEC.md
|
92
70
|
- lib/minuteman.rb
|
93
|
-
- lib/minuteman/
|
94
|
-
- lib/minuteman/
|
95
|
-
- lib/minuteman/
|
96
|
-
- lib/minuteman/
|
97
|
-
- lib/minuteman/
|
98
|
-
- lib/minuteman/
|
99
|
-
- lib/minuteman/
|
100
|
-
- lib/minuteman/
|
101
|
-
- lib/minuteman/
|
102
|
-
- lib/minuteman/
|
103
|
-
- lib/minuteman/time_spans/day.rb
|
104
|
-
- lib/minuteman/time_spans/hour.rb
|
105
|
-
- lib/minuteman/time_spans/minute.rb
|
106
|
-
- lib/minuteman/time_spans/month.rb
|
107
|
-
- lib/minuteman/time_spans/week.rb
|
108
|
-
- lib/minuteman/time_spans/year.rb
|
71
|
+
- lib/minuteman/analyzable.rb
|
72
|
+
- lib/minuteman/analyzer.rb
|
73
|
+
- lib/minuteman/configuration.rb
|
74
|
+
- lib/minuteman/counter.rb
|
75
|
+
- lib/minuteman/event.rb
|
76
|
+
- lib/minuteman/lua/operations.lua
|
77
|
+
- lib/minuteman/model.rb
|
78
|
+
- lib/minuteman/result.rb
|
79
|
+
- lib/minuteman/trigger.rb
|
80
|
+
- lib/minuteman/user.rb
|
109
81
|
- minuteman.gemspec
|
110
|
-
- test/
|
111
|
-
- test/
|
112
|
-
- test/
|
82
|
+
- test/helper.rb
|
83
|
+
- test/minuteman_bench.rb
|
84
|
+
- test/minuteman_test.rb
|
113
85
|
homepage: http://github.com/elcuervo/minuteman
|
114
86
|
licenses:
|
115
87
|
- MIT
|
116
88
|
- HUGWARE
|
89
|
+
metadata: {}
|
117
90
|
post_install_message:
|
118
91
|
rdoc_options: []
|
119
92
|
require_paths:
|
120
93
|
- lib
|
121
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
95
|
requirements:
|
124
|
-
- -
|
96
|
+
- - ">="
|
125
97
|
- !ruby/object:Gem::Version
|
126
98
|
version: '0'
|
127
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
-
none: false
|
129
100
|
requirements:
|
130
|
-
- -
|
101
|
+
- - ">"
|
131
102
|
- !ruby/object:Gem::Version
|
132
|
-
version:
|
103
|
+
version: 1.3.1
|
133
104
|
requirements: []
|
134
105
|
rubyforge_project:
|
135
|
-
rubygems_version:
|
106
|
+
rubygems_version: 2.2.2
|
136
107
|
signing_key:
|
137
|
-
specification_version:
|
108
|
+
specification_version: 4
|
138
109
|
summary: Bit Analytics
|
139
110
|
test_files:
|
140
|
-
- test/
|
141
|
-
- test/
|
142
|
-
- test/
|
111
|
+
- test/helper.rb
|
112
|
+
- test/minuteman_bench.rb
|
113
|
+
- test/minuteman_test.rb
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
minuteman (1.0.3)
|
5
|
-
redis (~> 3.0.3)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
given_core (3.0.0)
|
11
|
-
sorcerer (>= 0.3.7)
|
12
|
-
minitest (4.3.2)
|
13
|
-
minitest-given (3.0.0)
|
14
|
-
given_core (= 3.0.0)
|
15
|
-
minitest (> 4.3)
|
16
|
-
rake (0.9.2.2)
|
17
|
-
redis (3.0.3)
|
18
|
-
redis-namespace (1.2.1)
|
19
|
-
redis (~> 3.0.0)
|
20
|
-
sorcerer (1.0.0)
|
21
|
-
|
22
|
-
PLATFORMS
|
23
|
-
ruby
|
24
|
-
|
25
|
-
DEPENDENCIES
|
26
|
-
minitest (~> 4.3.0)
|
27
|
-
minitest-given (~> 3.0.0)
|
28
|
-
minuteman!
|
29
|
-
rake
|
30
|
-
redis-namespace (~> 1.2.1)
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require "minuteman/bit_operations/operation"
|
2
|
-
|
3
|
-
# Public: Minuteman core classs
|
4
|
-
#
|
5
|
-
class Minuteman
|
6
|
-
module BitOperations
|
7
|
-
extend Forwardable
|
8
|
-
|
9
|
-
def_delegators :Minuteman, :safe, :redis
|
10
|
-
|
11
|
-
# Public: Checks for the existance of ids on a given set
|
12
|
-
#
|
13
|
-
# ids - Array of ids
|
14
|
-
#
|
15
|
-
def include?(*ids)
|
16
|
-
result = ids.map { |id| getbit(id) }
|
17
|
-
result.size == 1 ? result.first : result
|
18
|
-
end
|
19
|
-
|
20
|
-
# Public: Resets the current key
|
21
|
-
#
|
22
|
-
def reset
|
23
|
-
safe { redis.rem(key) }
|
24
|
-
end
|
25
|
-
|
26
|
-
# Public: Cheks for the amount of ids stored on the current key
|
27
|
-
#
|
28
|
-
def length
|
29
|
-
safe { redis.bitcount(key) }
|
30
|
-
end
|
31
|
-
|
32
|
-
# Public: Calculates the NOT of the current key
|
33
|
-
#
|
34
|
-
def -@
|
35
|
-
operation("NOT", key)
|
36
|
-
end
|
37
|
-
alias :~@ :-@
|
38
|
-
|
39
|
-
# Public: Calculates the substract of one set to another
|
40
|
-
#
|
41
|
-
# timespan: Another BitOperations enabled class
|
42
|
-
#
|
43
|
-
def -(timespan)
|
44
|
-
operation("MINUS", timespan)
|
45
|
-
end
|
46
|
-
|
47
|
-
# Public: Calculates the XOR against another timespan
|
48
|
-
#
|
49
|
-
# timespan: Another BitOperations enabled class
|
50
|
-
#
|
51
|
-
def ^(timespan)
|
52
|
-
operation("XOR", timespan)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Public: Calculates the OR against another timespan
|
56
|
-
#
|
57
|
-
# timespan: Another BitOperations enabled class or an Array
|
58
|
-
#
|
59
|
-
def |(timespan)
|
60
|
-
operation("OR", timespan)
|
61
|
-
end
|
62
|
-
alias :+ :|
|
63
|
-
|
64
|
-
# Public: Calculates the AND against another timespan
|
65
|
-
#
|
66
|
-
# timespan: Another BitOperations enabled class or an Array
|
67
|
-
#
|
68
|
-
def &(timespan)
|
69
|
-
operation("AND", timespan)
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
# Private: Helper to access the value a given bit
|
75
|
-
#
|
76
|
-
# id: The bit
|
77
|
-
#
|
78
|
-
def getbit(id)
|
79
|
-
safe { redis.getbit(key, id) == 1 }
|
80
|
-
end
|
81
|
-
|
82
|
-
# Private: Cxecutes an operation between the current timespan and another
|
83
|
-
#
|
84
|
-
# type: The operation type
|
85
|
-
# timespan: The given timespan
|
86
|
-
#
|
87
|
-
def operation(type, timespan)
|
88
|
-
operate.call(type, timespan)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Private: Memoizes the operation class
|
92
|
-
#
|
93
|
-
def operate
|
94
|
-
@_operate ||= Operation.new(self)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "minuteman/bit_operations"
|
2
|
-
|
3
|
-
# Public: Minuteman core classs
|
4
|
-
#
|
5
|
-
class Minuteman
|
6
|
-
module BitOperations
|
7
|
-
# Public: The conversion of an array to an operable class
|
8
|
-
#
|
9
|
-
# key - The key where the result it's stored
|
10
|
-
# data - The original data of the intersection
|
11
|
-
#
|
12
|
-
class Data < Struct.new(:key, :data)
|
13
|
-
include BitOperations
|
14
|
-
include Enumerable
|
15
|
-
|
16
|
-
def to_ary
|
17
|
-
data
|
18
|
-
end
|
19
|
-
|
20
|
-
def size
|
21
|
-
data.size
|
22
|
-
end
|
23
|
-
|
24
|
-
def each(&block)
|
25
|
-
data.each(&block)
|
26
|
-
end
|
27
|
-
|
28
|
-
def ==(other)
|
29
|
-
other == data
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require "minuteman/bit_operations/plain"
|
2
|
-
require "minuteman/bit_operations/with_data"
|
3
|
-
|
4
|
-
# Public: Minuteman core classs
|
5
|
-
#
|
6
|
-
class Minuteman
|
7
|
-
module BitOperations
|
8
|
-
# Public: Handles the operations between two timespans
|
9
|
-
#
|
10
|
-
# type: The operation type
|
11
|
-
# timespan: One of the timespans to be permuted
|
12
|
-
# other: The other timespan to be permuted
|
13
|
-
#
|
14
|
-
class Operation < Struct.new(:timespan)
|
15
|
-
# Public: Caches operations against Array
|
16
|
-
#
|
17
|
-
class Cache
|
18
|
-
attr_reader :cache
|
19
|
-
|
20
|
-
def initialize
|
21
|
-
@cache = {}
|
22
|
-
end
|
23
|
-
|
24
|
-
# Public: Access a cached object
|
25
|
-
#
|
26
|
-
# array: The original data set
|
27
|
-
#
|
28
|
-
def [](array)
|
29
|
-
cache.fetch(array.sort.hash)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Public: Caches an object
|
33
|
-
#
|
34
|
-
# array: The original data set
|
35
|
-
# object: The object to be cached
|
36
|
-
#
|
37
|
-
def []=(array, object)
|
38
|
-
cache[array.sort.hash] = object
|
39
|
-
end
|
40
|
-
|
41
|
-
# Public: Checks for the existance of an array in the cache
|
42
|
-
#
|
43
|
-
# array: The original data set
|
44
|
-
#
|
45
|
-
def include?(array)
|
46
|
-
cache.keys.include?(array.sort.hash) if array.is_a?(Array)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
attr_reader :other
|
51
|
-
attr_accessor :cache
|
52
|
-
|
53
|
-
# Public: Initializes the Operation and starts the cache
|
54
|
-
#
|
55
|
-
def initialize(*)
|
56
|
-
super
|
57
|
-
|
58
|
-
@cache = Cache.new
|
59
|
-
end
|
60
|
-
|
61
|
-
# Public: Executes an operation
|
62
|
-
#
|
63
|
-
# type: The string type of the operation
|
64
|
-
# other: The other set to be operated, can be Array or BitOperations
|
65
|
-
#
|
66
|
-
def call(type, other)
|
67
|
-
@other = other
|
68
|
-
|
69
|
-
return minus_operation if type == "MINUS" && operable?
|
70
|
-
return cache[other] if cache.include?(other)
|
71
|
-
|
72
|
-
caching { klass.new(type, other, timespan.key).call }
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
# Private: Executes a minus operation between the sets
|
78
|
-
#
|
79
|
-
def minus_operation
|
80
|
-
timespan ^ (timespan & other)
|
81
|
-
end
|
82
|
-
|
83
|
-
# Private: Caches any caching capable operation
|
84
|
-
#
|
85
|
-
def caching
|
86
|
-
executed_class = yield
|
87
|
-
if other.is_a?(Array) && Minuteman.options[:cache]
|
88
|
-
cache[other] = executed_class
|
89
|
-
end
|
90
|
-
|
91
|
-
executed_class
|
92
|
-
end
|
93
|
-
|
94
|
-
# Private: returns the class to use for the operation
|
95
|
-
#
|
96
|
-
# timespan: The given timespan
|
97
|
-
#
|
98
|
-
def klass
|
99
|
-
case true
|
100
|
-
when other.is_a?(String), operable? then Plain
|
101
|
-
when other.is_a?(Array) then WithData
|
102
|
-
else raise(TypeError, "Unsupported type")
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# Private: Checks if a timespan is operable
|
107
|
-
#
|
108
|
-
# timespan: The given timespan
|
109
|
-
#
|
110
|
-
def operable?
|
111
|
-
other.class.ancestors.include?(BitOperations)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|