• Stars
    star
    410
  • Rank 105,468 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 16 years ago
  • Updated about 13 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TimelineFu

Easily build timelines, much like GitHub’s news feed.

Usage

TimelineFu requires you to have a TimelineEvent model. The simplest way is to use the generator.

$ script/generate timeline_fu && rake db:migrate
      exists  db/migrate
      create  db/migrate/20090333222034_create_timeline_events.rb
      create  app/models/timeline_event.rb
# Migration blabber...

Next step is to determine what generates an event in your various models.

class Post < ActiveRecord::Base
  #...
  belongs_to :author, :class_name => 'Person'
  fires :new_post, :on    => :create,
                   :actor => :author
end

You can add ‘fires’ statements to as many models as you want on as many models as you want.

They are hooked for you after standard ActiveRecord events. In the previous example, it’s an after_create on Posts.

Parameters for #fires

You can supply a few parameters to fires, two of them are mandatory.

  • the first param is a custom name for the event type. It’ll be your way of figuring out what events your reading back from the timeline_events table later.

    • :new_post in the example

The rest all fit neatly in an options hash.

  • :on => [ActiveRecord event]

    • mandatory. You use it to specify whether you want the event created after a create, update or destroy. You can also supply an array of events, e.g. [:create, :update].

  • :actor is your way of specifying who took this action.

    • In the example, post.author is going to be this person.

  • :subject is automatically set to self, which is good most of the time. You can however override it if you need to, using :subject.

  • :secondary_subject can let you specify something else that’s related to the event. A comment to a blog post would be a good example.

  • :if => symbol or proc/lambda lets you put conditions on when a TimelineEvent is created. It’s passed right to the after_xxx ActiveRecord event hook, so it’s has the same behavior.

Here’s another example:

class Comment < ActiveRecord::Base
  #...
  belongs_to :commenter, :class_name => 'Person'
  belongs_to :post
  fires :new_comment, :on                 => :create,
                      :actor              => :commenter,
                      #implicit :subject  => self,
                      :secondary_subject  => 'post',
                      :if => lambda { |comment| comment.commenter != comment.post.author }
end

TimelineEvent instantiation

The ActiveRecord event hook will automatically instantiate a TimelineEvent instance for you. It will receive the following parameters in #create!

  • event_type

    • “new_comment” in the comment example

  • actor

    • the commenter

  • subject

    • the comment instance

  • secondary_subject

    • the post instance

The generated model stores most of its info as polymorphic relationships.

class TimelineEvent < ActiveRecord::Base
  belongs_to :actor,              :polymorphic => true
  belongs_to :subject,            :polymorphic => true
  belongs_to :secondary_subject,  :polymorphic => true
end

How you actually get your timeline

To get your timeline you’ll probably have to create your own finder SQL or scopes (if your situation is extremely simple).

TimelineFu is not currently providing anything to generate your timeline because different situations will have wildly different requirements. Like access control issues and actually just what crazy stuff you’re cramming in that timeline.

We’re not saying it can’t be done, just that we haven’t done it yet. Contributions are welcome :-)

Get it

# Gemfile
gem "timeline_fu"

License

Copyright © 2008 James Golick, released under the MIT license

More Repositories

1

resource_controller

Rails RESTful controller abstraction plugin.
Ruby
498
star
2

degrade

Keep track of service error rates using redis. Degrade functionality if they're too high.
Ruby
310
star
3

active_presenter

The presenter library you already know.
Ruby
302
star
4

is_taggable

Tagging that doesn't want to be on steroids. It's skinny and happy to stay that way
Ruby
213
star
5

trample

A Better Load Simulator
Ruby
160
star
6

observational

Use the observer pattern to better divide your objects' responsibilities.
Ruby
116
star
7

attribute_fu

a better version of this functionality is in rails 2.3. use that!
Ruby
99
star
8

always_verify_ssl_certificates

Ruby's net/http is setup to never verify SSL certificates by default. Most ruby libraries do the same. That means that you're not verifying the identity of the server you're communicating with and are therefore exposed to man in the middle attacks. This gem monkey-patches net/http to force certificate verification and make turning it off impossible.
Ruby
97
star
9

blank

Blank is GiraffeSoft’s blank rails starter app.
Ruby
61
star
10

zebra

One line tests without the smells.
Ruby
56
star
11

enum_field

Ruby
55
star
12

statsd.scala

statsd on the jvm
Scala
48
star
13

conductor

Build clusters in the cloud with conductor.
Ruby
48
star
14

munin_plugin

Ruby
46
star
15

scala-resque-worker

Scala
44
star
16

action_messager

Dead simple IM notifications for your app
Ruby
43
star
17

cassandra-munin-plugins

Munin plugins for apache cassandra.
42
star
18

classy_resources

Think resource_controller, except for sinatra.
Ruby
41
star
19

lexical_uuid

UUIDs that are byte-ordered lamport clocks (timestamp, worker_id). Much simpler than type-1 UUID's crappy, weirdo layout.
Ruby
31
star
20

markaby

Markaby patched to run on rails 2.0.2
Ruby
23
star
21

tweet

Tweet from the command line.
Ruby
22
star
22

timeline_fu-example

Ruby
22
star
23

fetlife-nagios-plugins

Nagios plugins in use at FetLife. Services include: resque, cassandra, etc.
Ruby
22
star
24

lexical_uuid.erl

UUIDs that are byte-ordered lamport clocks (timestamp, worker_id). Much simpler than type-1 UUID's crappy, weirdo layout.
Erlang
21
star
25

openvpn-recipes

Get OpenVPN up and running on Ubuntu, using Chef. Great way to beat geofencing!
Ruby
19
star
26

dotfiles

Vim Script
17
star
27

friendly

http://jamesgolick.com/2009/12/16/introducing-friendly-nosql-with-mysql-in-ruby.html
Ruby
17
star
28

has_browser

has_browser makes it possible to create simple, parameterized browser interfaces to your models. That is, given a set of parameters, return all the models that match.
Ruby
16
star
29

conductor-rails

A rails stack for conductor.
Ruby
12
star
30

scrawny

a lightweight, RESTful persistent queue on top of thin, rack and invisible in < 60 LoC
Ruby
11
star
31

expectations

expectations is a lightweight unit testing framework.
Ruby
11
star
32

starling-on-invisible

Proof of concept that you can build a queueing server and client RESTfully, leveraging starling's persistent queue code, a lightweight web framework, and thin.
Ruby
10
star
33

scala-connection-pool

Connection pool abstractions in scala. Supports load balancing and failover in a thread-safe manner. Defers to commons-pool for the actual pooling.
Scala
9
star
34

spymemcached-gem

A jruby-only memcached client and rails cache store that uses spymemcached under the hood.
Ruby
7
star
35

action_mailer_verp

Send VERP emails with actionmailer. http://en.wikipedia.org/wiki/Variable_envelope_return_path
Ruby
7
star
36

dirty_callbacks

Ruby
6
star
37

per_mailer_smtp_settings

Setup different smtp settings per ActionMailer::Base subclass.
Ruby
6
star
38

memcache-lock

Extraction of the lock from cache-money.
Ruby
6
star
39

what_does_this_error_mean-rails

Rails plugin for integration with whatdoesthiserrormean.com
Ruby
6
star
40

file-sherpa

Upload progress bars for jQuery.
JavaScript
5
star
41

rollout_rest_api

A sinatra app that exposes a REST API for rollout.
Ruby
5
star
42

zfs-mysql-backup

4
star
43

fetlife-packages

Binary FreeBSD packages in use at fetlife.com (NSFW).
4
star
44

what_does_this_error_mean-merb

Ruby
3
star
45

sbt-ruby

sbt plugin for including ruby code and rubygems in the build.
Scala
3
star
46

smemcache

A scala wrapper around spymemcached.
Scala
3
star
47

rest_client-cocoa

Ruby
2
star
48

vim_conf

2
star
49

restful_roles

Ruby
2
star
50

rubyee-freebsd-port

Adapted from the ruby18 port. I'm new to freebsd and ports, so it's probably all wrong!
2
star
51

jgmalloc

C
2
star
52

health

Health checks for rails.
Ruby
2
star
53

activerecordless_migrations

Ruby
2
star
54

memcached.erl

because obviously I wanted to write a fucking memcached client
Erlang
2
star
55

gperftools

C++
2
star
56

r_c-2.1.1

2
star
57

tempo_cli

CLI for sending commands to tempo app.
Ruby
2
star
58

markdownj-gem

(J)Ruby wrapper around markdownj.
Ruby
1
star
59

telephos

A really simple Scala wrapper around Cassandra's thrift bindings. No DSLs here.
Scala
1
star
60

jruby-scala-issue

Ruby
1
star
61

client_proxy

Basic ruby proxy class to use around service clients that handles retrying requests and failover.
Ruby
1
star
62

thrift-exception-notifier

If you run thrift services in production, it's handy to receive an email when shit breaks.
Scala
1
star
63

uriparser

C
1
star
64

rpmspecs

RPM specs that I'm maintaining. I'm not good at this. They're probably all wrong.
1
star