Skip to content

Commit

Permalink
Replaced use of Loggable with BelongsToApp
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Evans committed Apr 30, 2010
1 parent 4d25533 commit 96bac6f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/dragonfly/analysis/base.rb
Expand Up @@ -2,7 +2,7 @@ module Dragonfly
module Analysis
class Base

include Loggable
include BelongsToApp
include Delegatable

end
Expand Down
4 changes: 4 additions & 0 deletions lib/dragonfly/belongs_to_app.rb
Expand Up @@ -10,6 +10,10 @@ def app
@app || raise(NotConfigured, "#{self.inspect} has no app set")
end

def app_set?
!!@app
end

def log
app.log
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dragonfly/data_storage/base.rb
Expand Up @@ -2,7 +2,7 @@ module Dragonfly
module DataStorage
class Base

include Loggable
include BelongsToApp

def store(temp_object)
raise NotImplementedError
Expand Down
5 changes: 3 additions & 2 deletions lib/dragonfly/delegator.rb
@@ -1,7 +1,7 @@
module Dragonfly
module Delegator

include Loggable
include BelongsToApp

# This gets raised if no delegated objects are able to handle
# the method call, even though they respond to that method.
Expand All @@ -10,8 +10,9 @@ class UnableToHandle < StandardError; end
def register(klass, *args, &block)
object = klass.new(*args)
object.configure(&block) if block
object.log = self.log if object.is_a?(Loggable)
object.app = self.app if app_set? && object.is_a?(BelongsToApp)
registered_objects << object
object
end

def unregister(klass)
Expand Down
2 changes: 1 addition & 1 deletion lib/dragonfly/encoding/base.rb
Expand Up @@ -2,7 +2,7 @@ module Dragonfly
module Encoding
class Base

include Loggable
include BelongsToApp
include Delegatable

def encode(*args)
Expand Down
2 changes: 1 addition & 1 deletion lib/dragonfly/processing/base.rb
Expand Up @@ -2,7 +2,7 @@ module Dragonfly
module Processing
class Base

include Loggable
include BelongsToApp
include Delegatable

end
Expand Down
19 changes: 14 additions & 5 deletions spec/dragonfly/belongs_to_app_spec.rb
Expand Up @@ -9,11 +9,16 @@ class Testoast
before(:each) do
@object = Testoast.new
end

it "should raise an error if the app is accessed but not set" do
lambda{
@object.app
}.should raise_error(Dragonfly::BelongsToApp::NotConfigured)

describe "when the app is not set" do
it "should raise an error if the app is accessed" do
lambda{
@object.app
}.should raise_error(Dragonfly::BelongsToApp::NotConfigured)
end
it "should say it's not set" do
@object.app_set?.should be_false
end
end

describe "when the app is set" do
Expand All @@ -29,6 +34,10 @@ class Testoast
it "should return the app's log" do
@object.log.should == @app.log
end

it "should say it's set" do
@object.app_set?.should be_true
end

end

Expand Down
20 changes: 11 additions & 9 deletions spec/dragonfly/delegator_spec.rb
Expand Up @@ -15,7 +15,7 @@ def clean(car)
end

class LorryDriver
include Dragonfly::Loggable
include Dragonfly::BelongsToApp
include Dragonfly::Delegatable

def drive(lorry)
Expand Down Expand Up @@ -59,13 +59,18 @@ def age; @age; end
@delegator.delegatable_methods.should == []
end

it "should return the object registered when registering" do
@delegator.register(CarDriver).should be_a(CarDriver)
end

end

describe "after registering a number of classes" do

before(:each) do
@delegator.register(CarDriver)
@delegator.register(LorryDriver)
@delegator.app = Dragonfly::App[:test]
@car_driver = @delegator.register(CarDriver)
@lorry_driver = @delegator.register(LorryDriver)
end

it "should raise an error when calling an unknown method" do
Expand Down Expand Up @@ -106,14 +111,11 @@ def age; @age; end
end

it "should return registered objects" do
objects = @delegator.registered_objects
objects.length.should == 2
objects[0].should be_a(CarDriver)
objects[1].should be_a(LorryDriver)
@delegator.registered_objects.should == [@car_driver, @lorry_driver]
end

it "should set the registered object's log to its own if loggable" do
@delegator.registered_objects[1].log.should == @delegator.log
it "should set the registered object's app to its own if object should belong to an app" do
@lorry_driver.app.should == @delegator.app
end

it "should enable unregistering classes" do
Expand Down

0 comments on commit 96bac6f

Please sign in to comment.