seymour 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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in seymour.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ task :default => :spec
data/lib/seymour.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "seymour/version"
2
+ require "seymour/redis"
3
+ require "seymour/activity_feed"
4
+
5
+ module Seymour
6
+ extend self
7
+
8
+ end
@@ -0,0 +1,50 @@
1
+ module Seymour
2
+ class ActivityFeed
3
+
4
+ attr_accessor :owner
5
+
6
+ def initialize(owner)
7
+ @owner = owner
8
+ end
9
+
10
+ def activity_ids
11
+ redis.lrange(key, 0, max_size).map{|id| id.to_i }
12
+ end
13
+
14
+ def push(activity, cmd = :lpush)
15
+ perform_push(activity.id, cmd) if should_push?(activity)
16
+ end
17
+
18
+ private
19
+
20
+ def redis
21
+ @redis ||= Seymour.redis
22
+ end
23
+
24
+ def key
25
+ "#{owner.class.name}:#{id_for_key}/#{feed_name}"
26
+ end
27
+
28
+ def id_for_key
29
+ owner.id
30
+ end
31
+
32
+ def feed_name
33
+ self.class.name.downcase
34
+ end
35
+
36
+ def max_size
37
+ 100
38
+ end
39
+
40
+ def should_push?(activity)
41
+ true
42
+ end
43
+
44
+ def perform_push(activity_id, cmd = :lpush)
45
+ redis.send(cmd, key, activity_id)
46
+ redis.ltrim(key, 0, max_size)
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ require 'redis-namespace'
2
+
3
+ module Seymour
4
+
5
+ ## Courtesy of resque
6
+ # Returns the current Redis connection. If none has been created, will
7
+ # create a new one.
8
+ def redis
9
+ return @redis if @redis
10
+ self.redis = Redis.respond_to?(:connect) ? Redis.connect : "localhost:6379"
11
+ self.redis
12
+ end
13
+
14
+ # Accepts:
15
+ # 1. A 'hostname:port' String
16
+ # 2. A 'hostname:port:db' String (to select the Redis db)
17
+ # 3. A 'hostname:port/namespace' String (to set the Redis namespace)
18
+ # 4. A Redis URL String 'redis://host:port'
19
+ # 5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
20
+ # or `Redis::Namespace`.
21
+ def redis=(server)
22
+ case server
23
+ when String
24
+ if server =~ /redis\:\/\//
25
+ redis = Redis.connect(:url => server, :thread_safe => true)
26
+ else
27
+ server, namespace = server.split('/', 2)
28
+ host, port, db = server.split(':')
29
+ redis = Redis.new(:host => host, :port => port,
30
+ :thread_safe => true, :db => db)
31
+ end
32
+ namespace ||= :seymour
33
+
34
+ @redis = Redis::Namespace.new(namespace, :redis => redis)
35
+ when Redis::Namespace
36
+ @redis = server
37
+ else
38
+ @redis = Redis::Namespace.new(:seymour, :redis => server)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Seymour
2
+ VERSION = "0.0.1"
3
+ end
data/seymour.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "seymour/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "seymour"
7
+ s.version = Seymour::VERSION
8
+ s.authors = ["Ross Kaffenberger"]
9
+ s.email = ["rosskaff@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Activity feed me, Seymour}
12
+ s.description = %q{For adding activity feeds to Rails application}
13
+
14
+ s.rubyforge_project = "seymour"
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
+
21
+ s.add_dependency "redis-namespace", "~> 1.1.0"
22
+
23
+ # specify any dependencies here; for example:
24
+ s.add_development_dependency "rspec"
25
+ # s.add_runtime_dependency "rest-client"
26
+ end
27
+
28
+ # gem build seymour.gemspec
29
+ # gem push seymour-x.x.x.gem
@@ -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-spec.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
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Seymour::ActivityFeed do
4
+
5
+ let(:owner) { mock("User", :id => 123) }
6
+ let(:feed) { Seymour::ActivityFeed.new(owner) }
7
+
8
+ describe "activity_ids" do
9
+ it "should return an empty list initially" do
10
+ feed.activity_ids.should == []
11
+ end
12
+ end
13
+
14
+ describe "push" do
15
+ it "adds id of given activity to activity_ids" do
16
+ feed.push mock("Activity", :id => 456)
17
+ feed.activity_ids.should == [456]
18
+ end
19
+ end
20
+
21
+ describe "owner" do
22
+ it "should return given owner" do
23
+ feed.owner.should == owner
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Seymour do
4
+
5
+ describe "redis" do
6
+ it "can set a namespace through a url-like string" do
7
+ Seymour.redis.should be_a(Redis::Namespace)
8
+ :seymour.should == Seymour.redis.namespace
9
+ Seymour.redis = 'localhost:9736/namespace'
10
+ 'namespace'.should == Seymour.redis.namespace
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ dir = File.dirname(File.expand_path(__FILE__))
2
+ $LOAD_PATH.unshift dir + '/../lib'
3
+
4
+ require 'seymour'
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rspec
8
+ end
9
+
10
+ at_exit do
11
+ pid = `ps -A -o pid,command | grep [r]edis-spec`.split(" ")[0]
12
+ puts "Killing test redis server..."
13
+ `rm -f #{dir}/dump.rdb`
14
+ Process.kill("KILL", pid.to_i)
15
+ exit $!.status
16
+ end
17
+
18
+ puts "Starting redis for testing at localhost:9736..."
19
+ `redis-server #{dir}/redis-spec.conf`
20
+ Seymour.redis = 'localhost:9736'
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seymour
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ross Kaffenberger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis-namespace
16
+ requirement: &70338425093600 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70338425093600
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70338425092600 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70338425092600
36
+ description: For adding activity feeds to Rails application
37
+ email:
38
+ - rosskaff@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .rspec
45
+ - Gemfile
46
+ - Rakefile
47
+ - lib/seymour.rb
48
+ - lib/seymour/activity_feed.rb
49
+ - lib/seymour/redis.rb
50
+ - lib/seymour/version.rb
51
+ - seymour.gemspec
52
+ - spec/redis-spec.conf
53
+ - spec/seymour/activity_feed_spec.rb
54
+ - spec/seymour_spec.rb
55
+ - spec/spec_helper.rb
56
+ homepage: ''
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: seymour
76
+ rubygems_version: 1.8.10
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Activity feed me, Seymour
80
+ test_files:
81
+ - spec/redis-spec.conf
82
+ - spec/seymour/activity_feed_spec.rb
83
+ - spec/seymour_spec.rb
84
+ - spec/spec_helper.rb