check_in 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/check_in.gemspec +61 -0
- data/lib/check_in/reader.rb +26 -0
- data/lib/check_in/writer.rb +105 -0
- data/lib/check_in.rb +38 -0
- data/spec/check_in_spec.rb +4 -0
- data/spec/redis-test.conf +115 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/writer_spec.rb +110 -0
- metadata +114 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Daniel Higginbotham
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= check_in
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Daniel Higginbotham. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "check_in"
|
8
|
+
gem.summary = %Q{Allow services to check in}
|
9
|
+
gem.description = %Q{Allow services to check in}
|
10
|
+
gem.email = "daniel@flyingmachinestudios.com"
|
11
|
+
gem.homepage = "http://github.com/flyingmachine/check_in"
|
12
|
+
gem.authors = ["Daniel Higginbotham"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_dependency "redis-namespace", ">= 0.10.0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "check_in #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/check_in.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
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
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{check_in}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Daniel Higginbotham"]
|
12
|
+
s.date = %q{2011-07-20}
|
13
|
+
s.description = %q{Allow services to check in}
|
14
|
+
s.email = %q{daniel@flyingmachinestudios.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"check_in.gemspec",
|
26
|
+
"lib/check_in.rb",
|
27
|
+
"lib/check_in/reader.rb",
|
28
|
+
"lib/check_in/writer.rb",
|
29
|
+
"spec/check_in_spec.rb",
|
30
|
+
"spec/redis-test.conf",
|
31
|
+
"spec/spec.opts",
|
32
|
+
"spec/spec_helper.rb",
|
33
|
+
"spec/writer_spec.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/flyingmachine/check_in}
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{Allow services to check in}
|
39
|
+
s.test_files = [
|
40
|
+
"spec/check_in_spec.rb",
|
41
|
+
"spec/spec_helper.rb",
|
42
|
+
"spec/writer_spec.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
51
|
+
s.add_runtime_dependency(%q<redis-namespace>, [">= 0.10.0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
54
|
+
s.add_dependency(%q<redis-namespace>, [">= 0.10.0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
58
|
+
s.add_dependency(%q<redis-namespace>, [">= 0.10.0"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CheckIn
|
2
|
+
class Reader
|
3
|
+
attr_reader :base
|
4
|
+
def initialize(base)
|
5
|
+
@base = base
|
6
|
+
end
|
7
|
+
|
8
|
+
def raw_checkins
|
9
|
+
CheckIn.redis.lrange(check_in_configuration.redis_key, 0, check_in_configuration.list_length)
|
10
|
+
end
|
11
|
+
|
12
|
+
def checkins
|
13
|
+
raw_checkins.collect do |c|
|
14
|
+
value, time = c.split(" | ")
|
15
|
+
{
|
16
|
+
:value => value,
|
17
|
+
:time => Time.parse(time)
|
18
|
+
}
|
19
|
+
end.sort{ |a, b| a.time <=> b.time }
|
20
|
+
end
|
21
|
+
|
22
|
+
def check_in_configuration
|
23
|
+
base.check_in_configuration
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module CheckIn
|
2
|
+
module Writer
|
3
|
+
|
4
|
+
def self.included(klass)
|
5
|
+
klass.class_eval do
|
6
|
+
class << self
|
7
|
+
attr_accessor :check_in_configuration
|
8
|
+
end
|
9
|
+
end
|
10
|
+
klass.check_in_configuration = Configuration.new(klass)
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_reader :base
|
16
|
+
|
17
|
+
def initialize(base)
|
18
|
+
@base = base
|
19
|
+
end
|
20
|
+
|
21
|
+
def service_name=(service_name)
|
22
|
+
@service_name = service_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def service_name
|
26
|
+
@service_name ||= base.name
|
27
|
+
end
|
28
|
+
|
29
|
+
def list_length=(list_length)
|
30
|
+
@list_length = list_length
|
31
|
+
end
|
32
|
+
|
33
|
+
def list_length
|
34
|
+
@list_length || 500
|
35
|
+
end
|
36
|
+
|
37
|
+
def instance_name_method=(instance_name_method)
|
38
|
+
@instance_name_method = instance_name_method
|
39
|
+
end
|
40
|
+
|
41
|
+
def instance_name_method
|
42
|
+
@instance_name_method ||= :to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
# redefine method to call check_in after original method is called
|
46
|
+
def check_in_after(method_name)
|
47
|
+
base.class_eval <<-END
|
48
|
+
alias_method :pre_check_in_#{method_name}, :#{method_name}
|
49
|
+
def #{method_name}(*args)
|
50
|
+
pre_check_in_#{method_name}(*args)
|
51
|
+
check_in(*args)
|
52
|
+
end
|
53
|
+
END
|
54
|
+
end
|
55
|
+
|
56
|
+
# redefine method to call check_in before original method is called
|
57
|
+
def check_in_before(method_name)
|
58
|
+
base.class_eval <<-END
|
59
|
+
alias_method :pre_check_in_#{method_name}, :#{method_name}
|
60
|
+
def #{method_name}(*args)
|
61
|
+
check_in(*args)
|
62
|
+
pre_check_in_#{method_name}(*args)
|
63
|
+
end
|
64
|
+
END
|
65
|
+
end
|
66
|
+
|
67
|
+
def redis_key
|
68
|
+
"checkins:#{service_name}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def setup(&block)
|
72
|
+
yield self
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def check_in(*args)
|
77
|
+
instance_name = send(check_in_configuration.instance_name_method)
|
78
|
+
time = Time.now.strftime(CheckIn.time_format)
|
79
|
+
line = "#{instance_name} | #{time}"
|
80
|
+
CheckIn.redis.rpush(check_in_configuration.redis_key, line)
|
81
|
+
trim_checkins
|
82
|
+
end
|
83
|
+
|
84
|
+
def trim_checkins
|
85
|
+
size = CheckIn.redis.llen(check_in_configuration.redis_key)
|
86
|
+
if size > check_in_configuration.list_length
|
87
|
+
CheckIn.redis.ltrim(check_in_configuration.redis_key, size - check_in_configuration.list_length, size - 1)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def check_in_configuration
|
92
|
+
# this is to allow usage on class methods
|
93
|
+
if self.class.respond_to?(:check_in_configuration)
|
94
|
+
self.class.check_in_configuration
|
95
|
+
else
|
96
|
+
self.class_eval do
|
97
|
+
class << self
|
98
|
+
check_in_configuration
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
data/lib/check_in.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'redis/namespace'
|
2
|
+
require 'check_in/writer'
|
3
|
+
require 'check_in/reader'
|
4
|
+
|
5
|
+
module CheckIn
|
6
|
+
class << self
|
7
|
+
|
8
|
+
# Accepts:
|
9
|
+
# 1. A 'hostname:port' string
|
10
|
+
# 2. A 'hostname:port:db' string (to select the Redis db)
|
11
|
+
# 3. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
|
12
|
+
# or `Redis::Namespace`.
|
13
|
+
def redis=(server)
|
14
|
+
if server.respond_to? :split
|
15
|
+
host, port, db = server.split(':')
|
16
|
+
redis = Redis.new(:host => host, :port => port,
|
17
|
+
:thread_safe => true, :db => db)
|
18
|
+
@redis = Redis::Namespace.new(:check_in, :redis => redis)
|
19
|
+
elsif server.respond_to? :namespace=
|
20
|
+
@redis = server
|
21
|
+
else
|
22
|
+
@redis = Redis::Namespace.new(:check_in, :redis => server)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def redis
|
27
|
+
@redis || raise("You must set the redis instance.")
|
28
|
+
end
|
29
|
+
|
30
|
+
def time_format=(format)
|
31
|
+
@time_format = format
|
32
|
+
end
|
33
|
+
|
34
|
+
def time_format
|
35
|
+
@time_format ||= "%b %d %Y %H:%M:%S"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# Redis configuration file example
|
2
|
+
|
3
|
+
# By default Redis does not run as a daemon. Use 'yes' if you need it.
|
4
|
+
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
|
5
|
+
daemonize yes
|
6
|
+
|
7
|
+
# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
|
8
|
+
# You can specify a custom pid file location here.
|
9
|
+
pidfile ./spec/redis-test.pid
|
10
|
+
|
11
|
+
# Accept connections on the specified port, default is 6379
|
12
|
+
port 9736
|
13
|
+
|
14
|
+
# If you want you can bind a single interface, if the bind option is not
|
15
|
+
# specified all the interfaces will listen for connections.
|
16
|
+
#
|
17
|
+
# bind 127.0.0.1
|
18
|
+
|
19
|
+
# Close the connection after a client is idle for N seconds (0 to disable)
|
20
|
+
timeout 300
|
21
|
+
|
22
|
+
# Save the DB on disk:
|
23
|
+
#
|
24
|
+
# save <seconds> <changes>
|
25
|
+
#
|
26
|
+
# Will save the DB if both the given number of seconds and the given
|
27
|
+
# number of write operations against the DB occurred.
|
28
|
+
#
|
29
|
+
# In the example below the behaviour will be to save:
|
30
|
+
# after 900 sec (15 min) if at least 1 key changed
|
31
|
+
# after 300 sec (5 min) if at least 10 keys changed
|
32
|
+
# after 60 sec if at least 10000 keys changed
|
33
|
+
save 900 1
|
34
|
+
save 300 10
|
35
|
+
save 60 10000
|
36
|
+
|
37
|
+
# The filename where to dump the DB
|
38
|
+
dbfilename dump.rdb
|
39
|
+
|
40
|
+
# For default save/load DB in/from the working directory
|
41
|
+
# Note that you must specify a directory not a file name.
|
42
|
+
dir ./spec/
|
43
|
+
|
44
|
+
# Set server verbosity to 'debug'
|
45
|
+
# it can be one of:
|
46
|
+
# debug (a lot of information, useful for development/testing)
|
47
|
+
# notice (moderately verbose, what you want in production probably)
|
48
|
+
# warning (only very important / critical messages are logged)
|
49
|
+
loglevel debug
|
50
|
+
|
51
|
+
# Specify the log file name. Also 'stdout' can be used to force
|
52
|
+
# the demon to log on the standard output. Note that if you use standard
|
53
|
+
# output for logging but daemonize, logs will be sent to /dev/null
|
54
|
+
logfile stdout
|
55
|
+
|
56
|
+
# Set the number of databases. The default database is DB 0, you can select
|
57
|
+
# a different one on a per-connection basis using SELECT <dbid> where
|
58
|
+
# dbid is a number between 0 and 'databases'-1
|
59
|
+
databases 16
|
60
|
+
|
61
|
+
################################# REPLICATION #################################
|
62
|
+
|
63
|
+
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
|
64
|
+
# another Redis server. Note that the configuration is local to the slave
|
65
|
+
# so for example it is possible to configure the slave to save the DB with a
|
66
|
+
# different interval, or to listen to another port, and so on.
|
67
|
+
|
68
|
+
# slaveof <masterip> <masterport>
|
69
|
+
|
70
|
+
################################## SECURITY ###################################
|
71
|
+
|
72
|
+
# Require clients to issue AUTH <PASSWORD> before processing any other
|
73
|
+
# commands. This might be useful in environments in which you do not trust
|
74
|
+
# others with access to the host running redis-server.
|
75
|
+
#
|
76
|
+
# This should stay commented out for backward compatibility and because most
|
77
|
+
# people do not need auth (e.g. they run their own servers).
|
78
|
+
|
79
|
+
# requirepass foobared
|
80
|
+
|
81
|
+
################################### LIMITS ####################################
|
82
|
+
|
83
|
+
# Set the max number of connected clients at the same time. By default there
|
84
|
+
# is no limit, and it's up to the number of file descriptors the Redis process
|
85
|
+
# is able to open. The special value '0' means no limts.
|
86
|
+
# Once the limit is reached Redis will close all the new connections sending
|
87
|
+
# an error 'max number of clients reached'.
|
88
|
+
|
89
|
+
# maxclients 128
|
90
|
+
|
91
|
+
# Don't use more memory than the specified amount of bytes.
|
92
|
+
# When the memory limit is reached Redis will try to remove keys with an
|
93
|
+
# EXPIRE set. It will try to start freeing keys that are going to expire
|
94
|
+
# in little time and preserve keys with a longer time to live.
|
95
|
+
# Redis will also try to remove objects from free lists if possible.
|
96
|
+
#
|
97
|
+
# If all this fails, Redis will start to reply with errors to commands
|
98
|
+
# that will use more memory, like SET, LPUSH, and so on, and will continue
|
99
|
+
# to reply to most read-only commands like GET.
|
100
|
+
#
|
101
|
+
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
|
102
|
+
# 'state' server or cache, not as a real DB. When Redis is used as a real
|
103
|
+
# database the memory usage will grow over the weeks, it will be obvious if
|
104
|
+
# it is going to use too much memory in the long run, and you'll have the time
|
105
|
+
# to upgrade. With maxmemory after the limit is reached you'll start to get
|
106
|
+
# errors for write operations, and this may even lead to DB inconsistency.
|
107
|
+
|
108
|
+
# maxmemory <bytes>
|
109
|
+
|
110
|
+
############################### ADVANCED CONFIG ###############################
|
111
|
+
|
112
|
+
# Glue small output buffers together in order to send small replies in a
|
113
|
+
# single TCP packet. Uses a bit more CPU but most of the times it is a win
|
114
|
+
# in terms of number of queries per second. Use 'yes' if unsure.
|
115
|
+
glueoutputbuf yes
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'check_in'
|
5
|
+
require 'spec'
|
6
|
+
require 'spec/autorun'
|
7
|
+
|
8
|
+
dir = File.dirname(File.expand_path(__FILE__))
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
config.before(:all) do
|
12
|
+
puts "Starting redis for testing at localhost:9736..."
|
13
|
+
`redis-server #{dir}/redis-test.conf`
|
14
|
+
CheckIn.redis = 'localhost:9736'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
at_exit do
|
19
|
+
pid = `ps -A -o pid,command | grep [r]edis-test`.split(" ")[0]
|
20
|
+
puts "Killing test redis server..."
|
21
|
+
`rm -f #{dir}/dump.rdb`
|
22
|
+
Process.kill("KILL", pid.to_i)
|
23
|
+
end
|
data/spec/writer_spec.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "CheckIn::Writer" do
|
4
|
+
before(:each) do
|
5
|
+
class TestClass
|
6
|
+
include CheckIn::Writer
|
7
|
+
|
8
|
+
def work(arg1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"identity"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
Object.send(:remove_const, :TestClass)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create a CheckInConfiguration constant in the class which included CheckIn::Recorder" do
|
22
|
+
lambda{TestClass::check_in_configuration}.should_not raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should default the service name to the name of the including class" do
|
26
|
+
TestClass::check_in_configuration.service_name.should == "TestClass"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should allow the service name to be set" do
|
30
|
+
TestClass::check_in_configuration.service_name = "blarg"
|
31
|
+
TestClass::check_in_configuration.service_name.should == "blarg"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have a list length of 500 by default" do
|
35
|
+
TestClass::check_in_configuration.list_length.should == 500
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should allow the list length to be set" do
|
39
|
+
TestClass::check_in_configuration.list_length = 2
|
40
|
+
TestClass::check_in_configuration.list_length.should == 2
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should default to :to_s for the instance name method" do
|
44
|
+
TestClass::check_in_configuration.instance_name_method.should == :to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should allow the instance name method to be set" do
|
48
|
+
TestClass::check_in_configuration.instance_name_method = :id
|
49
|
+
TestClass::check_in_configuration.instance_name_method.should == :id
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should allow configuration in a block" do
|
53
|
+
TestClass::check_in_configuration.setup do |c|
|
54
|
+
c.service_name = "harry potter"
|
55
|
+
c.list_length = 3
|
56
|
+
c.instance_name_method = :describe
|
57
|
+
end
|
58
|
+
|
59
|
+
TestClass::check_in_configuration.service_name.should == "harry potter"
|
60
|
+
TestClass::check_in_configuration.list_length.should == 3
|
61
|
+
TestClass::check_in_configuration.instance_name_method.should == :describe
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return the redis key" do
|
65
|
+
TestClass::check_in_configuration.redis_key.should == "checkins:TestClass"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should refer to CheckInConfiguration from instances" do
|
69
|
+
TestClass.new.check_in_configuration.should == TestClass::check_in_configuration
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should redefine work to call check_in" do
|
73
|
+
TestClass::check_in_configuration.check_in_after(:work)
|
74
|
+
t = TestClass.new
|
75
|
+
t.should_receive(:check_in).with("argity")
|
76
|
+
t.work("argity")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should redefine work to call check_in" do
|
80
|
+
TestClass::check_in_configuration.check_in_before(:work)
|
81
|
+
t = TestClass.new
|
82
|
+
t.should_receive(:check_in).with("argity")
|
83
|
+
t.work("argity")
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "checkin in" do
|
87
|
+
before(:each) do
|
88
|
+
TestClass::check_in_configuration.check_in_before(:work)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should record checkins" do
|
92
|
+
t = TestClass.new
|
93
|
+
t.work("test")
|
94
|
+
|
95
|
+
r = CheckIn::Reader.new(TestClass)
|
96
|
+
raw_checkin = r.raw_checkins[0]
|
97
|
+
|
98
|
+
raw_checkin.should match(/^identity \| \w{3} \d\d \d{4} \d\d:\d\d:\d\d$/)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should keep only the number of checkins specified by list_length" do
|
102
|
+
TestClass::check_in_configuration.list_length = 2
|
103
|
+
t = TestClass.new
|
104
|
+
3.times{t.work("test")}
|
105
|
+
|
106
|
+
r = CheckIn::Reader.new(TestClass)
|
107
|
+
r.raw_checkins.size.should == 2
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: check_in
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Daniel Higginbotham
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-20 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: redis-namespace
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 55
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 10
|
49
|
+
- 0
|
50
|
+
version: 0.10.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Allow services to check in
|
54
|
+
email: daniel@flyingmachinestudios.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files:
|
60
|
+
- LICENSE
|
61
|
+
- README.rdoc
|
62
|
+
files:
|
63
|
+
- .document
|
64
|
+
- LICENSE
|
65
|
+
- README.rdoc
|
66
|
+
- Rakefile
|
67
|
+
- VERSION
|
68
|
+
- check_in.gemspec
|
69
|
+
- lib/check_in.rb
|
70
|
+
- lib/check_in/reader.rb
|
71
|
+
- lib/check_in/writer.rb
|
72
|
+
- spec/check_in_spec.rb
|
73
|
+
- spec/redis-test.conf
|
74
|
+
- spec/spec.opts
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- spec/writer_spec.rb
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://github.com/flyingmachine/check_in
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.3.7
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Allow services to check in
|
111
|
+
test_files:
|
112
|
+
- spec/check_in_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- spec/writer_spec.rb
|