showcase 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9da87d3e97f733f9798a5d4db0ba8ead0e96fd81
4
- data.tar.gz: c007232eadcecbc5447f520772e0a2eb7a2ff75a
3
+ metadata.gz: c765d3877ec138551a3f31f9689b060b8461a433
4
+ data.tar.gz: 59dcf8ad2c8b36965df56f5edb950beed2ddcfc8
5
5
  SHA512:
6
- metadata.gz: f69407adef169d083d54fa092d2c3e981ffc414354932a6f171fdfc73136ee62a6f2cdce2179f01a8909b97da198d4018f471d410494e991629c0fdd2ce71f3b
7
- data.tar.gz: 512c10d3efbf4592b558b29c1f6cc2df340e0d9715e8dc64160c69dc97266348f289a05666beb3c667a3f0c1709b293640fecaea62747c7703b4c51d54b51f20
6
+ metadata.gz: db97e02df789e59db7f735b2414ebcdb469dcca9de3323ab36598556bd77802ed56c15f3f93658aabf9b04f8c1208699405db96a5011a992f9296c334ef26219
7
+ data.tar.gz: 7b23bfa80dd5a1c5ac4968c8704f8260cb7d4c5a845ddef8e1fc8579f5ec4bb7dd19f362c956698573b60fc43a0b3a2c1ab76b8d8510c6f85455533dcd585f49
@@ -14,12 +14,8 @@ module Showcase
14
14
  end
15
15
 
16
16
  def present(obj, klass = nil, context = presenter_context)
17
- if obj.is_a? ::Showcase::Presenter
18
- obj
19
- else
20
- klass ||= "#{obj.class.name}Presenter".constantize
21
- klass.new(obj, context)
22
- end
17
+ klass ||= "#{obj.class.name}Presenter".constantize
18
+ klass.new(obj, context)
23
19
  end
24
20
 
25
21
  def present_collection(obj, klass = nil, context = presenter_context)
@@ -2,23 +2,30 @@ require 'delegate'
2
2
  require 'showcase/helpers'
3
3
 
4
4
  module Showcase
5
- class Presenter < SimpleDelegator
6
- include Helpers
7
-
5
+ class Presenter < BasicObject
8
6
  attr_reader :view_context
9
-
10
- alias_method :object, :__getobj__
7
+ attr_reader :object
11
8
  alias_method :h, :view_context
12
9
 
13
- def class
14
- object.class
15
- end
10
+ include Helpers
16
11
 
17
- def initialize(obj, context)
18
- super(obj)
12
+ def initialize(object, context)
13
+ @object = object
19
14
  @view_context = context
20
15
  end
21
16
 
17
+ def respond_to?(name)
18
+ if [:view_context, :h, :object].include? name
19
+ true
20
+ else
21
+ object.respond_to?(name)
22
+ end
23
+ end
24
+
25
+ def method_missing(name, *args, &block)
26
+ object.__send__(name, *args, &block)
27
+ end
28
+
22
29
  def self.presents(*attrs)
23
30
  attrs.each do |attr|
24
31
  define_method attr do
@@ -1,3 +1,3 @@
1
1
  module Showcase
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -43,7 +43,7 @@ describe Showcase::Presenter do
43
43
  end
44
44
 
45
45
  describe '#presents_collection' do
46
- it 'wraps the specifieed collection attributes inside a presenter' do
46
+ it 'wraps the specified collection attributes inside a presenter' do
47
47
  subject.collaborators.first.sex.should == 'male'
48
48
  end
49
49
  it 'passes the context' do
@@ -57,25 +57,17 @@ describe Showcase::Helpers do
57
57
  let(:context) { Context.new }
58
58
 
59
59
  describe '.present' do
60
- context 'when the passed object is already a Showcase::Base' do
61
- it 'returns the object itself' do
62
- presenter = PersonPresenter.new(object, stub)
63
- context.present(presenter).should == presenter
64
- end
60
+ it 'instanciate a new presenter, inferring the class' do
61
+ PersonPresenter.stub(:new).with(object, context).and_return 'Presenter'
62
+ context.present(object, PersonPresenter).should == 'Presenter'
65
63
  end
66
- context 'when the object still needs to be presented' do
67
- it 'instanciate a new presenter, inferring the class' do
68
- PersonPresenter.stub(:new).with(object, context).and_return 'Presenter'
69
- context.present(object, PersonPresenter).should == 'Presenter'
70
- end
71
- it 'the presenter class to use can be specified as the second parameter' do
72
- ProjectPresenter.stub(:new).with(object, context).and_return 'Presenter'
73
- context.present(object, ProjectPresenter).should == 'Presenter'
74
- end
75
- it 'the context to use can be specified as third parameter' do
76
- different_context = stub
77
- context.present(object, ProjectPresenter, different_context).view_context.should == different_context
78
- end
64
+ it 'the presenter class to use can be specified as the second parameter' do
65
+ ProjectPresenter.stub(:new).with(object, context).and_return 'Presenter'
66
+ context.present(object, ProjectPresenter).should == 'Presenter'
67
+ end
68
+ it 'the context to use can be specified as third parameter' do
69
+ different_context = stub
70
+ context.present(object, ProjectPresenter, different_context).view_context.should == different_context
79
71
  end
80
72
  end
81
73
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: showcase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-12 00:00:00.000000000 Z
11
+ date: 2013-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport