Skip to content

Commit

Permalink
Added some README docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Jun 1, 2008
1 parent 9a53a93 commit d235b13
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.textile
Expand Up @@ -13,4 +13,4 @@ Including
* ActiveRecord-style finders
* Adapters for your favorite repository or database type
* Integration with your favorite web frameworks
* Voyeurs for watching do things. Think observers.
* Voyeurs for watching resources. Think observers.
29 changes: 28 additions & 1 deletion dm-voyeur/README
@@ -1,3 +1,30 @@
README
========================================================================
dm-voyeur was developed by: markbates
DataMapper::Voyeur allows you to add callback hooks to many models. This is similar to observers in ActiveRecord.

Example:
class Adam
include DataMapper::Resource

property :id, Integer, :serial => true
property :name, String
end

class AdamVoyeur
include DataMapper::Voyeur

peep Adam

before :save do
# log message
end

before :get_drunk do
# eat something
end

after_class_method :unite do
raise "Call for help!"
end

end
4 changes: 4 additions & 0 deletions dm-voyeur/lib/dm-voyeur.rb
@@ -1,4 +1,6 @@
module DataMapper
# Voyeur's allow you to add callback hooks to DataMapper::Resource objects in a separate class. This is great
# for separating out logic that is not really part of the model, but needs to be triggered by a model, or models.
module Voyeur

def self.included(klass)
Expand All @@ -13,6 +15,8 @@ def initialize
self.neighborhood_watch = []
end

# Assign an Array of Class names to watch.
# peep User, Article, Topic
def peep(*args)
# puts "#{self.to_s} peeping... #{args.collect{|c| DataMapper::Inflection.classify(c.to_s)}.join(', ')}"
self.neighborhood_watch = args
Expand Down

0 comments on commit d235b13

Please sign in to comment.