Skip to content

Commit

Permalink
exhibit as inheritance. Fix issue objects-on-rails#22
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexParamonov committed Nov 5, 2012
1 parent e089563 commit 20e9645
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
35 changes: 11 additions & 24 deletions lib/display_case/exhibit.rb
Expand Up @@ -19,29 +19,6 @@ def self.inherited(child)
@@exhibits << child
end

def self.pointer=(pointer)
# TODO should should be @pointer
@@pointer = pointer
end

def self.pointer
@@pointer
end

def pointer
__class__.pointer
end

# def pointer
# self.__class__.pointer || begin
# if respond_to? :__getobg__
# __getobg__.pointer
# else
# self
# end
# end
# end

def self.exhibit(object, context=nil)
return object if exhibited_object?(object)
if defined? Rails
Expand All @@ -54,7 +31,6 @@ def self.exhibit(object, context=nil)
exhibits.inject(object) do |object, exhibit_class|
exhibit_class.exhibit_if_applicable(object, context)
end.tap do |obj|
self.pointer = obj
Rails.logger.debug "Exhibits applied: #{obj.inspect_exhibits}" if defined? Rails
end
end
Expand Down Expand Up @@ -103,6 +79,17 @@ def self.object_is_any_of?(object, *classes)
def initialize(model, context)
@context = context
super(model)
@pointer ||= self
self.pointer = @pointer
end

def pointer=(pointer)
@pointer = pointer
__getobj__.pointer = pointer if __getobj__.respond_to? :pointer=
end

def pointer
@pointer
end

alias_method :__class__, :class
Expand Down
4 changes: 1 addition & 3 deletions spec/integration/several_exhibits_spec.rb
Expand Up @@ -42,7 +42,6 @@ def render
end

it "should not be influenced by other manual exhibitions" do
skip "fix it to allow custom exhibitions"
other_exhibit = new_exhibit
mock.instance_of(other_exhibit).title
object = other_exhibit.new(@exhibited, stub!)
Expand All @@ -53,11 +52,10 @@ def render
end
end

@exhibited.render
object.render
end

it "should not be influenced by other calls to exhibit" do
skip "fix it to allow multiple calls to .exhibit"
# other exhibition
@exhibits = [new_exhibit, new_exhibit]
stub(DisplayCase::Exhibit).exhibits { @exhibits }
Expand Down

0 comments on commit 20e9645

Please sign in to comment.