lifestreamable 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +9 -1
- data/README.rdoc +1 -0
- data/lib/lifestreamable/lifestreamable.rb +67 -5
- data/lifestreamable.gemspec +1 -2
- metadata +2 -3
- data/PostInstall.txt +0 -7
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
History.txt
|
2
2
|
Manifest.txt
|
3
|
-
PostInstall.txt
|
4
3
|
README.rdoc
|
5
4
|
Rakefile
|
5
|
+
generators/lifestreamable_migration/lifestreamable_migration_generator.rb
|
6
|
+
generators/lifestreamable_migration/templates/migration.rb
|
6
7
|
lib/lifestreamable.rb
|
8
|
+
lib/lifestreamable/create_observer.rb
|
9
|
+
lib/lifestreamable/destroy_observer.rb
|
10
|
+
lib/lifestreamable/lifestream_observer.rb
|
11
|
+
lib/lifestreamable/lifestreamable.rb
|
12
|
+
lib/lifestreamable/lifestreamed.rb
|
13
|
+
lib/lifestreamable/observer.rb
|
14
|
+
lib/lifestreamable/update_observer.rb
|
7
15
|
script/console
|
8
16
|
script/destroy
|
9
17
|
script/generate
|
data/README.rdoc
CHANGED
@@ -1,7 +1,68 @@
|
|
1
|
-
# :title:
|
1
|
+
# :title: Lifestreamable
|
2
|
+
# == DESCRIPTION:
|
3
|
+
#
|
4
|
+
# Lifestreamable is a rails gem that allows social network life lifestream operations. A lifestream is a series of events that occured and that are related to an owner.
|
5
|
+
# It has been designed to collect data upfront in model observers to minimize the number of request done at display time. the goal being that if the lifestream dislays several types of data over several different models, then only a single query will be run to get all the data to display instead of querying all data for each model. this radiaclly cuts down on display time.
|
6
|
+
# This is a port to a gem of the lifestream libraries that have been designed for the sports social network legrandclub.rds.ca
|
7
|
+
#
|
8
|
+
# == INSTALLATION:
|
9
|
+
# * gem install lifestreamable
|
10
|
+
# * script/generate lifestreamable_migration
|
11
|
+
#
|
12
|
+
# == SYNOPSIS:
|
13
|
+
#
|
14
|
+
# Ths lifestream modules is made up of 2 mixins, the lifestreamable, and lifestreamed modules.
|
15
|
+
# The lifestreamed module is included for models that own events, while the lifestreamable module is included on each model that triggers the event.
|
16
|
+
#
|
17
|
+
# for example, a user can write posts and comments, we want to report in the user's lifestream that the user has written posts and comments.
|
18
|
+
#
|
19
|
+
# defining the owner class
|
20
|
+
# class User < ActiveRecord::Base
|
21
|
+
# lifestreamed :order=>'id asc' # <= overrides the normal order which is 'id desc'
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# defining the event classes
|
25
|
+
# class Post < ActiveRecord::Base
|
26
|
+
# belongs_to :user
|
27
|
+
# has_many :comments
|
28
|
+
# lifestreamable :on=>[:create, :update, :destroy], data=>:get_data, :owner=>:user
|
29
|
+
#
|
30
|
+
# def get_data # this method must return a data structure that is serializable by YAML
|
31
|
+
# {
|
32
|
+
# :user=>{:firstname=>self.user.firstname, :lastname=>self.user.lastname},
|
33
|
+
# :post=>{:title=>self.title}
|
34
|
+
# }
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# class Comment < ActiveRecord::Base
|
39
|
+
# belongs_to :user
|
40
|
+
# belongs_to :post
|
41
|
+
# # another way to get the data is through a Proc
|
42
|
+
# lifestreamable :on=>[:create, :update, :destroy], :owner=>:user, data=> lambda {|model|
|
43
|
+
# {
|
44
|
+
# :user=>{:firstname=>model.user.firstname, :lastname=>model.user.lastname},
|
45
|
+
# :post=>{:title=>model.post.title},
|
46
|
+
# :comment=>{:body=>model.body}
|
47
|
+
# }
|
48
|
+
# }
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# Whenever a new post is created, it will create a new entry in the lifestream model. To get the lifestream from the owner:
|
52
|
+
# user=User.first
|
53
|
+
#
|
54
|
+
# # get the lifestream for the user
|
55
|
+
# lifestream = user.lifestream #=> returns an array of Lifestreamable::Lifesteam model instances
|
56
|
+
#
|
57
|
+
# #get the data that was stored
|
58
|
+
# data = lifestream.first.object_data
|
59
|
+
#
|
60
|
+
#
|
61
|
+
# == module Lifestreamable
|
62
|
+
#
|
2
63
|
# module for models that trigger lifestream events.
|
3
64
|
#
|
4
|
-
# Usage:
|
65
|
+
# == Usage:
|
5
66
|
# class Post < ActiveRecord::Base
|
6
67
|
# belongs_to :user
|
7
68
|
# lifestreamable :on=>[:create, :update, :destroy], :data=>:get_data, :owner=>:user
|
@@ -11,7 +72,7 @@
|
|
11
72
|
# end
|
12
73
|
# end
|
13
74
|
#
|
14
|
-
# Options
|
75
|
+
# == Options
|
15
76
|
# Note, when using Proc for the options, the model that triggers the event is always passed to the Proc.
|
16
77
|
# ex. Proc.new {|model| ... }
|
17
78
|
#
|
@@ -32,7 +93,7 @@
|
|
32
93
|
# * :update_instead_of_destroy => Specifies if a the last entry should be updated in the lifestream when a :destroy event is triggered. can be true, false, a Proc or a function name.
|
33
94
|
#
|
34
95
|
#
|
35
|
-
# Usage with all options
|
96
|
+
# == Usage with all options
|
36
97
|
# class Post < ActiveRecord::Base
|
37
98
|
# belongs_to :user
|
38
99
|
# lifestreamable :on=>[:create, :update, :destroy],
|
@@ -72,7 +133,8 @@
|
|
72
133
|
#
|
73
134
|
# end
|
74
135
|
#
|
75
|
-
#
|
136
|
+
# == NOTICE
|
137
|
+
# the insertion into the lifestream is done as an after filter in the controller. when debigging in the console, you may want to generate the lifestream, in this case, call Lifestreamable::Lifestreamer.generate_lifestream
|
76
138
|
|
77
139
|
module Lifestreamable
|
78
140
|
Struct.new('LifestreamData', :reference_type, :reference_id, :owner_type, :owner_id, :stream_type, :object_data_hash)
|
data/lifestreamable.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{lifestreamable}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Benoit Goyette"]
|
@@ -11,7 +11,6 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.email = %q{benoit.goyette@gmail.com}
|
12
12
|
s.files = ["History.txt",
|
13
13
|
"Manifest.txt",
|
14
|
-
"PostInstall.txt",
|
15
14
|
"README.rdoc",
|
16
15
|
"Rakefile",
|
17
16
|
"generators/lifestreamable_migration/lifestreamable_migration_generator.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Benoit Goyette
|
@@ -29,7 +29,6 @@ extra_rdoc_files: []
|
|
29
29
|
files:
|
30
30
|
- History.txt
|
31
31
|
- Manifest.txt
|
32
|
-
- PostInstall.txt
|
33
32
|
- README.rdoc
|
34
33
|
- Rakefile
|
35
34
|
- generators/lifestreamable_migration/lifestreamable_migration_generator.rb
|