Class: Goalkeeper

Inherits:
Object
  • Object
show all
Defined in:
lib/goalkeeper.rb,
lib/goalkeeper/version.rb

Overview

Goalkeeper provides methods to track if specific events(Goals) have been completed(met).

It is not a complicated system and it is easy enough to roll your own. This is an extraction from a system Pharos EI has been using.

A Goal is just a unique string. It is up to your application to define any schema for the Goal's label.

For example you might have your Goals labeled by date and company id:

"job:2016-01-17:company:7"

When a Goal is met a record is created in Redis with a timestamp, this is the only persistent layer.

Goalkeeper.met!("jobkey")
# or
Goalkeeper::Goal.new("jobkey").met!

To check if a Goal as been met

Goalkeeper::Goal.new("jobkey").met?

Customize the redis client by setting it in your application

Goalkeeper.redis = your_redis_client

Each record has a default expiration of 24 hours, but this can be modified.

Goalkeeper.expiration = number_of_seconds

Redis keys are stored under the default namespace of “Goalkeeper:”. The namespace can be configured:

Goalkeeper.namespace = string

Defined Under Namespace

Classes: Goal, List

Constant Summary collapse

VERSION =
"0.2"

Class Method Summary collapse

Class Method Details

.expirationObject

The TTL set for each met Goal record created in Redis Default is 24 hours


54
55
56
# File 'lib/goalkeeper.rb', line 54

def self.expiration
  @expiration ||= 24 * 60 * 60
end

.expiration=(number_of_seconds) ⇒ Object

Overwrite the default expiration


59
60
61
# File 'lib/goalkeeper.rb', line 59

def self.expiration=(number_of_seconds)
  @expiration = number_of_seconds
end

.met!(label) ⇒ Object

Creates a persistent Goal market with the given label.


48
49
50
# File 'lib/goalkeeper.rb', line 48

def self.met!(label)
  Goal.new(label).met!
end

.namespaceObject


63
64
65
# File 'lib/goalkeeper.rb', line 63

def self.namespace
  @namespace ||= "Goalkeeper"
end

.namespace=(ns) ⇒ Object


67
68
69
# File 'lib/goalkeeper.rb', line 67

def self.namespace=(ns)
  @namespace = ns
end

.redisObject


43
44
45
# File 'lib/goalkeeper.rb', line 43

def self.redis
  @redis ||= Redis.new
end

.redis=(redis) ⇒ Object

Set the Redis client to a non default setting


39
40
41
# File 'lib/goalkeeper.rb', line 39

def self.redis=(redis)
  @redis = redis
end