Skip to content

Commit

Permalink
Renamed dm-voyeur to dm-observer
Browse files Browse the repository at this point in the history
Did these renamings:
  dm-voyeur -> dm_observer
  Voyeur -> Observer
  peep -> observe
  neighborhood_watch -> observing

Did the renaming because:
  * it makes this plugin easier to find
  * the new name is more family friendly
  • Loading branch information
David James committed Jun 12, 2008
1 parent 8d432c6 commit 6db3ffe
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README
Expand Up @@ -8,7 +8,7 @@ Including:
* Migrations
* Validations
* Aggregates
* Voyeurs
* Observers

== Aggregates

Expand Down
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 resources. Think observers.
* Observers for watching resources.
3 changes: 2 additions & 1 deletion Rakefile
Expand Up @@ -27,12 +27,13 @@ gem_paths = %w[
dm-is-nested_set
dm-is-tree
dm-migrations
dm-observer
dm-serializer
dm-shorthand
dm-timestamps
dm-types
dm-validations
dm-voyeur

merb_datamapper
]
gems = gem_paths.map { |p| File.basename(p) }
Expand Down
File renamed without changes.
14 changes: 8 additions & 6 deletions dm-voyeur/README → dm-observer/README
@@ -1,19 +1,21 @@
README
========================================================================
DataMapper::Voyeur allows you to add callback hooks to many models. This is similar to observers in ActiveRecord.
======
DataMapper::Observer 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 AdamObserver
include DataMapper::Observer

class AdamVoyeur
include DataMapper::Voyeur

peep Adam
observe Adam

before :save do
# log message
Expand Down
4 changes: 2 additions & 2 deletions dm-voyeur/Rakefile → dm-observer/Rakefile
Expand Up @@ -8,7 +8,7 @@ require 'pathname'
CLEAN.include '{log,pkg}/'

spec = Gem::Specification.new do |s|
s.name = 'dm-voyeur'
s.name = 'dm-observer'
s.version = '0.9.1'
s.platform = Gem::Platform::RUBY
s.has_rdoc = true
Expand All @@ -17,7 +17,7 @@ spec = Gem::Specification.new do |s|
s.description = s.summary
s.author = 'Mark Bates'
s.email = 'mark@mackframework.com'
s.homepage = 'http://github.com/sam/dm-more/tree/master/dm-voyeur'
s.homepage = 'http://github.com/sam/dm-more/tree/master/dm-observer'
s.require_path = 'lib'
s.files = FileList[ '{lib,spec}/**/*.rb', 'spec/spec.opts', 'Rakefile', *s.extra_rdoc_files ]
s.add_dependency('dm-core', "=#{s.version}")
Expand Down
File renamed without changes.
35 changes: 18 additions & 17 deletions dm-voyeur/lib/dm-voyeur.rb → dm-observer/lib/dm-observer.rb
@@ -1,54 +1,55 @@
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
# Observers 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 Observer

def self.included(klass)
klass.extend(ClassMethods)
end

module ClassMethods

attr_accessor :neighborhood_watch
attr_accessor :observing

def initialize
self.neighborhood_watch = []
self.observing = []
end

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

def before(sym, &block)
self.neighborhood_watch.each do |klass|
self.observing.each do |klass|
klass.before(sym.to_sym, &block)
end
end

def after(sym, &block)
self.neighborhood_watch.each do |klass|
self.observing.each do |klass|
klass.after(sym.to_sym, &block)
end
end

def before_class_method(sym, &block)
self.neighborhood_watch.each do |klass|
self.observing.each do |klass|
klass.before_class_method(sym.to_sym, &block)
end
end

def after_class_method(sym, &block)
self.neighborhood_watch.each do |klass|
self.observing.each do |klass|
klass.after_class_method(sym.to_sym, &block)
end
end

end # ClassMethods

end # Voyeur
end # Observer
end # DataMapper

if $0 == __FILE__
Expand All @@ -69,10 +70,10 @@ class Foo

Foo.auto_migrate!

class FooVoyeur
include DataMapper::Voyeur
class FooObserver
include DataMapper::Observer

peep :foo
observe :foo

before :save do
raise "Hell!" if self.bar.nil?
Expand Down
@@ -1,7 +1,7 @@
require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'

describe DataMapper::Voyeur do
describe DataMapper::Observer do
before :all do
class Adam
include DataMapper::Resource
Expand Down Expand Up @@ -53,10 +53,10 @@ def empty?
Alcohol::Beer.auto_migrate!


class AdamVoyeur
include DataMapper::Voyeur
class AdamObserver
include DataMapper::Observer

peep Adam
observe Adam

before :save do
@falling = true
Expand All @@ -72,10 +72,10 @@ class AdamVoyeur

end

class DrinkingVoyeur
include DataMapper::Voyeur
class DrinkingObserver
include DataMapper::Observer

peep Adam, Alcohol::Beer
observe Adam, Alcohol::Beer

after :drink do
@refrigerated = true
Expand All @@ -102,18 +102,18 @@ class DrinkingVoyeur
@adam.done.should be_nil
end

it "peep should add a class to the neighborhood watch" do
AdamVoyeur.should have(1).neighborhood_watch
AdamVoyeur.neighborhood_watch.first.should == Adam
it "observe should add a class to the neighborhood watch" do
AdamObserver.should have(1).observing
AdamObserver.observing.first.should == Adam
end

it "peep should add more than one class to the neighborhood watch" do
DrinkingVoyeur.should have(2).neighborhood_watch
DrinkingVoyeur.neighborhood_watch.first.should == Adam
DrinkingVoyeur.neighborhood_watch[1].should == Alcohol::Beer
it "observe should add more than one class to the neighborhood watch" do
DrinkingObserver.should have(2).observing
DrinkingObserver.observing.first.should == Adam
DrinkingObserver.observing[1].should == Alcohol::Beer
end

it "should peep multiple classes with the same method name" do
it "should observe multiple classes with the same method name" do
@adam.should_not be_happy
@beer.should_not be_empty
@adam.drink
Expand Down
File renamed without changes.
Expand Up @@ -4,7 +4,7 @@
gem "dm-core"
require 'dm-core'
require 'pathname'
require Pathname(__FILE__).dirname.parent.expand_path + 'lib/dm-voyeur'
require Pathname(__FILE__).dirname.parent.expand_path + 'lib/dm-observer'

def load_driver(name, default_uri)
return false if ENV['ADAPTER'] != name.to_s
Expand Down

0 comments on commit 6db3ffe

Please sign in to comment.