Skip to content

Commit

Permalink
Merge pull request drapergem#25 from edtsech/block
Browse files Browse the repository at this point in the history
Ability to pass block to decorator method
  • Loading branch information
jcasimir committed Oct 3, 2011
2 parents 6521360 + 16f69ee commit 1f4c1e7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/draper/model_support.rb
@@ -1,5 +1,6 @@
module Draper::ModelSupport
def decorator
@decorator ||= "#{self.class.name}Decorator".constantize.decorate(self)
block_given? ? yield(@decorator) : @decorator
end
end
5 changes: 5 additions & 0 deletions spec/draper/model_support_spec.rb
Expand Up @@ -6,5 +6,10 @@
describe '#decorator' do
its(:decorator) { should be_kind_of(ProductDecorator) }
its(:decorator) { should be(subject.decorator) }

it 'should have abillity to pass block' do
a = Product.new.decorator { |d| d.awesome_title }
a.should eql "Awesome Title"
end
end
end
2 changes: 1 addition & 1 deletion spec/samples/active_record.rb
@@ -1,4 +1,4 @@
module ActiveRecord
class Base
end
end
end
4 changes: 4 additions & 0 deletions spec/samples/product_decorator.rb
@@ -1,3 +1,7 @@
class ProductDecorator < Draper::Base
decorates :product

def awesome_title
"Awesome Title"
end
end

0 comments on commit 1f4c1e7

Please sign in to comment.