dam 0.1.0 → 0.2.0
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 +1 -0
- data/README.markdown +52 -2
- data/Rakefile +2 -0
- data/lib/dam.rb +4 -2
- data/lib/dam/stream.rb +8 -8
- data/lib/dam/version.rb +1 -1
- data/test/stream_test.rb +13 -0
- metadata +3 -2
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/*
|
data/README.markdown
CHANGED
@@ -1,2 +1,52 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Dam
|
2
|
+
===
|
3
|
+
|
4
|
+
A ruby framework for Activity Streams, using Redis as a backend
|
5
|
+
|
6
|
+
Assuming you have added gemcutter.org to your ruby gems sources, dam is easy to install using
|
7
|
+
|
8
|
+
gem install dam
|
9
|
+
|
10
|
+
Using Dam
|
11
|
+
=========
|
12
|
+
|
13
|
+
You need to configure dam to connect to your current redis installation. To do that, put this line somewhere in your code
|
14
|
+
Dam::Storage.database = Redis.new
|
15
|
+
|
16
|
+
First, define your activities. You can use any attributes you wish, and give blocks or static values, as long as they are serializable to json
|
17
|
+
|
18
|
+
require 'dam'
|
19
|
+
Dam.activity :comment_posted do
|
20
|
+
author { "name" => params[:comment].user.name, "id" => params[:comment].user.id }
|
21
|
+
published { params[:comment].created_at.to_s }
|
22
|
+
comment { "id" => params[:comment].id, "excerpt" => params[:comment].excerpt }
|
23
|
+
action "post"
|
24
|
+
end
|
25
|
+
|
26
|
+
Then declare streams that will accepts these activities
|
27
|
+
|
28
|
+
require 'dam'
|
29
|
+
Dam.stream :activities_from_bob do
|
30
|
+
limit 10
|
31
|
+
accepts :action => "post", :author => {"name" => "bob"}
|
32
|
+
end
|
33
|
+
|
34
|
+
Finally, just post your activities:
|
35
|
+
Dam.post :comment_posted, :comment => my_comment
|
36
|
+
|
37
|
+
And access the stream's activities using:
|
38
|
+
Dam::Stream[:activities_from_bob].all.each {|activity| puts activity.comment["excerpt"] }
|
39
|
+
|
40
|
+
Further possibilities
|
41
|
+
=====================
|
42
|
+
|
43
|
+
You can create _templated_ streams, that is, streams who first have to be instantiated to start receiving activities. To do this, use a route-like name, such as
|
44
|
+
|
45
|
+
Dam.stream "project/:project" do
|
46
|
+
limit 15
|
47
|
+
accepts :project => {"id" => params[:project]}
|
48
|
+
end
|
49
|
+
|
50
|
+
You can then instantiate these projects to start receiving events
|
51
|
+
|
52
|
+
Dam::Stream["project/12345"].instantiate!
|
data/Rakefile
CHANGED
data/lib/dam.rb
CHANGED
@@ -13,9 +13,11 @@ module Dam
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.post(type, params = {})
|
16
|
-
act =
|
16
|
+
act = Dam::ActivityType.lookup(type.to_sym).apply(params)
|
17
17
|
|
18
|
-
act.
|
18
|
+
act.post!
|
19
|
+
|
20
|
+
act
|
19
21
|
end
|
20
22
|
|
21
23
|
def self.activity(name, &block)
|
data/lib/dam/stream.rb
CHANGED
@@ -65,7 +65,7 @@ module Dam
|
|
65
65
|
|
66
66
|
def instances
|
67
67
|
elems = Dam::Storage.database.keys("stream:" + @glob_pattern)
|
68
|
-
elems.
|
68
|
+
elems.collect {|elem| apply(elem) }
|
69
69
|
end
|
70
70
|
|
71
71
|
def matches? what
|
@@ -188,23 +188,23 @@ module Dam
|
|
188
188
|
# match a nil element with a nil condition
|
189
189
|
return condition.nil? if element.nil?
|
190
190
|
|
191
|
-
if condition.respond_to? :each_pair
|
191
|
+
if condition.respond_to? :each_pair # condition is a hash
|
192
192
|
condition.all? do |key, value|
|
193
|
-
(
|
193
|
+
eval_condition(value, element[key])
|
194
194
|
end
|
195
195
|
else
|
196
|
-
condition
|
196
|
+
eval_condition(condition, element)
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
200
|
-
def
|
200
|
+
def eval_condition(arg, val)
|
201
201
|
case arg
|
202
202
|
when ParamsProxy
|
203
|
-
@params[arg.key]
|
203
|
+
@params[arg.key] == val
|
204
204
|
when Proc
|
205
|
-
arg.call
|
205
|
+
arg.call(val)
|
206
206
|
else
|
207
|
-
arg
|
207
|
+
arg == val
|
208
208
|
end
|
209
209
|
end
|
210
210
|
end
|
data/lib/dam/version.rb
CHANGED
data/test/stream_test.rb
CHANGED
@@ -103,4 +103,17 @@ context "a parameterized stream" do
|
|
103
103
|
topic.kind_of(Dam::Stream)
|
104
104
|
asserts("matches a valid activity") { topic.matches? Dam::Activity[:comment].apply(:author => "bob") }
|
105
105
|
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "a stream with a proc condition" do
|
109
|
+
setup do
|
110
|
+
Dam::Storage.clear!
|
111
|
+
Dam.stream :with_a_proc do
|
112
|
+
accepts :author => { "name" => Proc.new {|name| name.reverse == name} }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
topic.kind_of(Dam::Stream)
|
117
|
+
asserts("matches a valid activity") { topic.matches? Dam::Activity[:comment].apply(:author => "abcba") }
|
118
|
+
asserts("rejects an invalid activity") { !topic.matches? Dam::Activity[:comment].apply(:author => "not valid") }
|
106
119
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Philippe Bougie
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-24 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -62,6 +62,7 @@ extra_rdoc_files:
|
|
62
62
|
- LICENSE
|
63
63
|
- README.markdown
|
64
64
|
files:
|
65
|
+
- .gitignore
|
65
66
|
- LICENSE
|
66
67
|
- README.markdown
|
67
68
|
- Rakefile
|