goalkeeper 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +8 -0
- data/goalkeeper.gemspec +25 -0
- data/lib/goalkeeper.rb +98 -0
- data/lib/goalkeeper/version.rb +3 -0
- data/test/goalkeeper_test.rb +102 -0
- data/test/test_helper.rb +5 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e12557dafed1d9031a7a11e69d2c4acd39665cf8
|
4
|
+
data.tar.gz: 87d0150ba4b4b3c6f72d6577308f3dbbb60d30b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5053c93b993f256c6b91000713ed079058a0b1179cd6ca58e0aeefb5e6ec8dd69188ba091ed8bb5e23f1dd8fdede9e72ba348e01c408a9066521da81e08c5fa0
|
7
|
+
data.tar.gz: 2eafd8b2593bd2f4ce935089fceb606f2ee954a412d771558ce349f5a00c56aebfe7d92f2d7d1d0036326ec13ed6862ffba10a91004dad9d0ad9d20310ddc747
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 John Weir
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Goalkeeper
|
2
|
+
|
3
|
+
Goalkeeper is a simple system for tracking if system wide requirements have been met. It is a TODO list for your application.
|
4
|
+
|
5
|
+
An example usage would be validating if each customer was sent a daily report.
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'goalkeeper'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install goalkeeper
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/jweir/goalkeeper/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/goalkeeper.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'goalkeeper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "goalkeeper"
|
8
|
+
spec.version = Goalkeeper::VERSION
|
9
|
+
spec.authors = ["John Weir"]
|
10
|
+
spec.email = ["john@smokinggun.com"]
|
11
|
+
spec.summary = %q{A Todo App for your application.}
|
12
|
+
spec.description = %q{Goalkeeper is a system for validation that specific goals have been met by an application.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "redis", "~> 3"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
data/lib/goalkeeper.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require "goalkeeper/version"
|
2
|
+
require 'forwardable'
|
3
|
+
require 'redis'
|
4
|
+
|
5
|
+
class Goalkeeper
|
6
|
+
|
7
|
+
# Creates a persistent Goal market with the given label.
|
8
|
+
def self.met!(label)
|
9
|
+
Goal.new(label).met!
|
10
|
+
end
|
11
|
+
|
12
|
+
class List
|
13
|
+
extend Forwardable
|
14
|
+
def_delegators :@list, :size, :[]
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@list = []
|
18
|
+
end
|
19
|
+
|
20
|
+
# Creates a new Goal.
|
21
|
+
# see Goal#new for usage
|
22
|
+
def add(label, ref: nil)
|
23
|
+
@list.push(Goal.new(label, ref: ref))
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def met?
|
28
|
+
unmet.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
def unmet
|
32
|
+
@list.select {|g| ! g.met?}
|
33
|
+
end
|
34
|
+
|
35
|
+
def met
|
36
|
+
@list.select {|g| g.met?}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Goal
|
41
|
+
attr_reader :label
|
42
|
+
attr_reader :ref
|
43
|
+
|
44
|
+
# +label+ is a unique string to identify this demand.
|
45
|
+
# There is no checking if it is truly unique.
|
46
|
+
#
|
47
|
+
# +ref+ is an optional reference to any object. This
|
48
|
+
# would be used by the end user's application.
|
49
|
+
def initialize(label, ref: nil)
|
50
|
+
@label = label
|
51
|
+
@ref = ref
|
52
|
+
end
|
53
|
+
|
54
|
+
def met!
|
55
|
+
Store.write(self.label)
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
def met?
|
60
|
+
! Store.read(self.label).nil?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Store
|
65
|
+
EXPIRATION = 60 * 60 * 24 # 1 day
|
66
|
+
|
67
|
+
def self.write(label)
|
68
|
+
nl = ns(label)
|
69
|
+
client.set nl, Time.now
|
70
|
+
client.expire nl, EXPIRATION
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.read(label)
|
74
|
+
nl = ns(label)
|
75
|
+
client.get nl
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.remove(label)
|
79
|
+
nl = ns(label)
|
80
|
+
client.del nl
|
81
|
+
end
|
82
|
+
|
83
|
+
protected
|
84
|
+
|
85
|
+
def self.ns(label)
|
86
|
+
namespace + ":"+ label
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.namespace
|
90
|
+
"Goalkeeper"
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.client
|
94
|
+
@client ||= Redis.new
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# API
|
4
|
+
# Goal.configure
|
5
|
+
# Goal.met label, ttl
|
6
|
+
# Goal::List.new
|
7
|
+
# .add
|
8
|
+
# .met
|
9
|
+
# .unmet
|
10
|
+
# .met?
|
11
|
+
#
|
12
|
+
# configure
|
13
|
+
# redis client
|
14
|
+
# namespace
|
15
|
+
#
|
16
|
+
# Goal -> score, completed, met
|
17
|
+
#
|
18
|
+
# was a Goal met?
|
19
|
+
# when was it met?
|
20
|
+
describe Goalkeeper do
|
21
|
+
|
22
|
+
describe Goalkeeper::List do
|
23
|
+
before do
|
24
|
+
@goals = Goalkeeper::List.new
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#add" do
|
28
|
+
it "create a Goal" do
|
29
|
+
@goals.add("a:1")
|
30
|
+
assert_equal 1, @goals.size
|
31
|
+
assert_equal "a:1", @goals[0].label
|
32
|
+
end
|
33
|
+
|
34
|
+
it "accepts an optional reference object" do
|
35
|
+
o = Object.new
|
36
|
+
@goals.add("a:1", ref: o)
|
37
|
+
assert_equal o, @goals[0].ref
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return itself (so it is chainable)" do
|
41
|
+
assert_equal @goals, @goals.add("a:1")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#met" do
|
46
|
+
it "returns all Goals which have been met"
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#unmet" do
|
50
|
+
it "returns all Goals which have not been met"
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#met?" do
|
54
|
+
it "is true when all Goals have been met"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "met!" do
|
59
|
+
it "should create a Goal for the given label" do
|
60
|
+
assert Goalkeeper.met!("x:1")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "has a default ttl expiration"
|
64
|
+
it "takes an optional at: timestamp"
|
65
|
+
it "takes an optional ttl for expiration"
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "namespace" do
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "configuation" do
|
72
|
+
# allow setting the redis client
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "Integration" do
|
77
|
+
before do
|
78
|
+
puts "fix this!"
|
79
|
+
Redis.new.flushdb
|
80
|
+
end
|
81
|
+
|
82
|
+
it "works like this" do
|
83
|
+
Goalkeeper.met! "x"
|
84
|
+
|
85
|
+
d = Goalkeeper::List
|
86
|
+
.new
|
87
|
+
.add("x")
|
88
|
+
.add("y")
|
89
|
+
|
90
|
+
assert_equal false, d.met?
|
91
|
+
|
92
|
+
assert_equal ["y"], d.unmet.map(&:label)
|
93
|
+
assert_equal ["x"], d.met.map(&:label)
|
94
|
+
|
95
|
+
Goalkeeper.met! "y"
|
96
|
+
|
97
|
+
assert_equal true, d.met?
|
98
|
+
|
99
|
+
assert_equal ["x","y"], d.met.map(&:label)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goalkeeper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Weir
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Goalkeeper is a system for validation that specific goals have been met
|
56
|
+
by an application.
|
57
|
+
email:
|
58
|
+
- john@smokinggun.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- goalkeeper.gemspec
|
69
|
+
- lib/goalkeeper.rb
|
70
|
+
- lib/goalkeeper/version.rb
|
71
|
+
- test/goalkeeper_test.rb
|
72
|
+
- test/test_helper.rb
|
73
|
+
homepage: ''
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A Todo App for your application.
|
97
|
+
test_files:
|
98
|
+
- test/goalkeeper_test.rb
|
99
|
+
- test/test_helper.rb
|