classic_presenter 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -4
- data/Gemfile +4 -4
- data/Gemfile.lock +32 -32
- data/README.rdoc +93 -94
- data/Rakefile +1 -1
- data/classic_presenter.gemspec +23 -23
- data/lib/classic_presenter.rb +5 -5
- data/lib/classic_presenter/base.rb +25 -21
- data/lib/classic_presenter/helper.rb +11 -11
- data/lib/classic_presenter/railtie.rb +9 -9
- data/lib/classic_presenter/version.rb +3 -3
- data/lib/generators/presenter_generator.rb +10 -10
- data/lib/generators/templates/presenter.rb +2 -2
- data/spec/classic_presenter_base_spec.rb +35 -35
- data/spec/classic_presenter_helper_spec.rb +15 -15
- data/spec/dummy_presenter_spec.rb +17 -0
- data/spec/spec_helper.rb +8 -7
- metadata +13 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6ca2f243124bf5574ec8b514b4225e0391a49a7e
|
4
|
+
data.tar.gz: e8dd15ba4de3b41b9ee4fdf40a645d3c738834f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78475c31fa1519f8cb6edd133d90ba61cdc59a999551edb74b9f5aa14c863df180e2a7e032150cd911a805c151a6ac27d3271735e9c05c9107435c9572348640
|
7
|
+
data.tar.gz: c9c59e188f864d4e0be766647fc07a46f1207ca50f949f391b4f81f13335e12b25afd8c055090ee04824806e21c4b4b67d52c80324f6d7f42077de1ade2cb653
|
data/.gitignore
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
*~
|
2
|
-
.bundle
|
3
|
-
rdoc/*
|
4
|
-
pkg
|
1
|
+
*~
|
2
|
+
.bundle
|
3
|
+
rdoc/*
|
4
|
+
pkg
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in classic_presenter.gemspec
|
4
|
-
gemspec
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in classic_presenter.gemspec
|
4
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
classic_presenter (1.0.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
coderay (1.0.9)
|
10
|
-
diff-lcs (1.1.3)
|
11
|
-
method_source (0.8.1)
|
12
|
-
pry (0.9.12.1)
|
13
|
-
coderay (~> 1.0.5)
|
14
|
-
method_source (~> 0.8)
|
15
|
-
slop (~> 3.4)
|
16
|
-
rspec (2.10.0)
|
17
|
-
rspec-core (~> 2.10.0)
|
18
|
-
rspec-expectations (~> 2.10.0)
|
19
|
-
rspec-mocks (~> 2.10.0)
|
20
|
-
rspec-core (2.10.0)
|
21
|
-
rspec-expectations (2.10.0)
|
22
|
-
diff-lcs (~> 1.1.3)
|
23
|
-
rspec-mocks (2.10.1)
|
24
|
-
slop (3.4.4)
|
25
|
-
|
26
|
-
PLATFORMS
|
27
|
-
ruby
|
28
|
-
|
29
|
-
DEPENDENCIES
|
30
|
-
classic_presenter!
|
31
|
-
pry
|
32
|
-
rspec
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
classic_presenter (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.0.9)
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
method_source (0.8.1)
|
12
|
+
pry (0.9.12.1)
|
13
|
+
coderay (~> 1.0.5)
|
14
|
+
method_source (~> 0.8)
|
15
|
+
slop (~> 3.4)
|
16
|
+
rspec (2.10.0)
|
17
|
+
rspec-core (~> 2.10.0)
|
18
|
+
rspec-expectations (~> 2.10.0)
|
19
|
+
rspec-mocks (~> 2.10.0)
|
20
|
+
rspec-core (2.10.0)
|
21
|
+
rspec-expectations (2.10.0)
|
22
|
+
diff-lcs (~> 1.1.3)
|
23
|
+
rspec-mocks (2.10.1)
|
24
|
+
slop (3.4.4)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
classic_presenter!
|
31
|
+
pry
|
32
|
+
rspec
|
data/README.rdoc
CHANGED
@@ -1,94 +1,93 @@
|
|
1
|
-
== Classic Presenter
|
2
|
-
|
3
|
-
Presenter Pattern for Rails Applications
|
4
|
-
|
5
|
-
== Installation
|
6
|
-
|
7
|
-
gem install classic_presenter
|
8
|
-
|
9
|
-
== Usage
|
10
|
-
|
11
|
-
* In your Gemfile you should set:
|
12
|
-
|
13
|
-
gem 'classic_presenter'
|
14
|
-
|
15
|
-
* Create a simple ActiveRecord class that you want to present:
|
16
|
-
|
17
|
-
class Product < ActiveRecord::Base
|
18
|
-
end
|
19
|
-
|
20
|
-
* Create a presenter class inheriting from ClassicPresenter::Base:
|
21
|
-
|
22
|
-
class ProductPresenter < ClassicPresenter::Base
|
23
|
-
def display_name
|
24
|
-
if context.user_logged_in?
|
25
|
-
name
|
26
|
-
else
|
27
|
-
context.link_to name, context.product_path
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def display_description
|
32
|
-
context.render "products/description", :product => self
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
* In your view, show.html.erb for example, you can present your Product object using this syntax:
|
37
|
-
|
38
|
-
<% present ProductPresenter, @product do |presenter| %>
|
39
|
-
<%= presenter.display_name %>
|
40
|
-
<%= presenter.display_description %>
|
41
|
-
<% end %>
|
42
|
-
|
43
|
-
== Cool Features
|
44
|
-
|
45
|
-
* You can decorates a collection of objects with your presenter:
|
46
|
-
|
47
|
-
#products_controller.rb
|
48
|
-
@products = ProductPresenter.map(Post.all, view_context)
|
49
|
-
|
50
|
-
* Inside of the presenter we have an access to the context. In the example above the context is the View(ActionView), then we can access any method like
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
<%= @product.
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
== Classic Presenter
|
2
|
+
|
3
|
+
Presenter Pattern for Rails Applications
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install classic_presenter
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
* In your Gemfile you should set:
|
12
|
+
|
13
|
+
gem 'classic_presenter'
|
14
|
+
|
15
|
+
* Create a simple ActiveRecord class that you want to present:
|
16
|
+
|
17
|
+
class Product < ActiveRecord::Base
|
18
|
+
end
|
19
|
+
|
20
|
+
* Create a presenter class inheriting from ClassicPresenter::Base:
|
21
|
+
|
22
|
+
class ProductPresenter < ClassicPresenter::Base
|
23
|
+
def display_name
|
24
|
+
if context.user_logged_in?
|
25
|
+
name
|
26
|
+
else
|
27
|
+
context.link_to name, context.product_path
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def display_description
|
32
|
+
context.render "products/description", :product => self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
* In your view, show.html.erb for example, you can present your Product object using this syntax:
|
37
|
+
|
38
|
+
<% present ProductPresenter, @product do |presenter| %>
|
39
|
+
<%= presenter.display_name %>
|
40
|
+
<%= presenter.display_description %>
|
41
|
+
<% end %>
|
42
|
+
|
43
|
+
== Cool Features
|
44
|
+
|
45
|
+
* You can decorates a collection of objects with your presenter:
|
46
|
+
|
47
|
+
#products_controller.rb
|
48
|
+
@products = ProductPresenter.map(Post.all, view_context)
|
49
|
+
|
50
|
+
* Inside of the presenter we have an access to the context. In the example above the context is the View(ActionView), then we can access any method like link_to, number_to_currency etc directly.
|
51
|
+
|
52
|
+
* You can also instantiate your presenter in the controller using the view_context and then to access any helper method like number_to_currency:
|
53
|
+
|
54
|
+
#products_controller.rb
|
55
|
+
@product = ProductPresenter.new(Product.find(params[:id]), view_context)
|
56
|
+
|
57
|
+
class ProductPresenter < ClassicPresenter::Base
|
58
|
+
def price
|
59
|
+
context.number_to_currency(price, :precision => 3)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
* Since ClassicPresenter::Base is a Decorator, it implements the “transparent interface” requirements of the Gang of Four’s definition. This means that when we call some method in ProductPresenter, it will be delegated to the decorated object (in this case Product), like this:
|
64
|
+
|
65
|
+
#products_controller.rb
|
66
|
+
@product = ProductPresenter.new(Product.find(params[:id]))
|
67
|
+
|
68
|
+
#show.html.erb
|
69
|
+
<%= @product.name %>
|
70
|
+
<%= @product.display_name %>
|
71
|
+
|
72
|
+
== License
|
73
|
+
|
74
|
+
(The MIT License)
|
75
|
+
|
76
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
77
|
+
a copy of this software and associated documentation files (the
|
78
|
+
'Software'), to deal in the Software without restriction, including
|
79
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
80
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
81
|
+
permit persons to whom the Software is furnished to do so, subject to
|
82
|
+
the following conditions:
|
83
|
+
|
84
|
+
The above copyright notice and this permission notice shall be
|
85
|
+
included in all copies or substantial portions of the Software.
|
86
|
+
|
87
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
88
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
89
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
90
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
91
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
92
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
93
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
1
|
+
require "bundler/gem_tasks"
|
data/classic_presenter.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "classic_presenter/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "classic_presenter"
|
7
|
-
s.version = ClassicPresenter::VERSION
|
8
|
-
s.authors = ["Rinaldi Fonseca"]
|
9
|
-
s.email = ["rinaldifonseca@gmail.com"]
|
10
|
-
s.homepage = ""
|
11
|
-
s.summary = %q{A simple Presenter Pattern for Rails Applications}
|
12
|
-
s.description = %q{A simple Presenter Pattern for Rails Applications}
|
13
|
-
|
14
|
-
s.rubyforge_project = "classic_presenter"
|
15
|
-
|
16
|
-
s.files = `git ls-files`.split("\n")
|
17
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
|
21
|
-
s.add_development_dependency "rspec"
|
22
|
-
s.add_development_dependency "pry"
|
23
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "classic_presenter/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "classic_presenter"
|
7
|
+
s.version = ClassicPresenter::VERSION
|
8
|
+
s.authors = ["Rinaldi Fonseca"]
|
9
|
+
s.email = ["rinaldifonseca@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{A simple Presenter Pattern for Rails Applications}
|
12
|
+
s.description = %q{A simple Presenter Pattern for Rails Applications}
|
13
|
+
|
14
|
+
s.rubyforge_project = "classic_presenter"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
s.add_development_dependency "pry"
|
23
|
+
end
|
data/lib/classic_presenter.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require "classic_presenter/version"
|
2
|
-
require "delegate"
|
3
|
-
require "classic_presenter/base"
|
4
|
-
require "classic_presenter/helper"
|
5
|
-
require "classic_presenter/railtie"
|
1
|
+
require "classic_presenter/version"
|
2
|
+
require "delegate"
|
3
|
+
require "classic_presenter/base"
|
4
|
+
require "classic_presenter/helper"
|
5
|
+
require "classic_presenter/railtie"
|
@@ -1,21 +1,25 @@
|
|
1
|
-
module ClassicPresenter
|
2
|
-
class Base < SimpleDelegator
|
3
|
-
attr_accessor :context
|
4
|
-
|
5
|
-
def initialize(model, context = nil, objects = {})
|
6
|
-
objects.each do |key, value|
|
7
|
-
self.class.send :define_method, key do
|
8
|
-
value
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
@context = context
|
13
|
-
super model
|
14
|
-
end
|
15
|
-
|
16
|
-
def
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
|
1
|
+
module ClassicPresenter
|
2
|
+
class Base < SimpleDelegator
|
3
|
+
attr_accessor :context
|
4
|
+
|
5
|
+
def initialize(model, context = nil, objects = {})
|
6
|
+
objects.each do |key, value|
|
7
|
+
self.class.send :define_method, key do
|
8
|
+
value
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
@context = context
|
13
|
+
super model
|
14
|
+
end
|
15
|
+
|
16
|
+
def target
|
17
|
+
self.__getobj__
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.map(collection, context = nil)
|
21
|
+
collection.map {|item| self.new(item, context)}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module ClassicPresenter
|
2
|
-
module Helper
|
3
|
-
extend self
|
4
|
-
|
5
|
-
def present(presenter_class, model = nil, objects = {})
|
6
|
-
presenter = presenter_class.new(model, self, objects)
|
7
|
-
yield presenter if block_given?
|
8
|
-
presenter
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module ClassicPresenter
|
2
|
+
module Helper
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def present(presenter_class, model = nil, objects = {})
|
6
|
+
presenter = presenter_class.new(model, self, objects)
|
7
|
+
yield presenter if block_given?
|
8
|
+
presenter
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module ClassicPresenter
|
2
|
-
class Railtie < Rails::Railtie
|
3
|
-
initializer "classic_presenter.configure_rails_initialization" do |app|
|
4
|
-
ActiveSupport.on_load :action_controller do
|
5
|
-
helper ::ClassicPresenter::Helper
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
1
|
+
module ClassicPresenter
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer "classic_presenter.configure_rails_initialization" do |app|
|
4
|
+
ActiveSupport.on_load :action_controller do
|
5
|
+
helper ::ClassicPresenter::Helper
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module ClassicPresenter
|
2
|
-
VERSION = "1.0
|
3
|
-
end
|
1
|
+
module ClassicPresenter
|
2
|
+
VERSION = "1.1.0"
|
3
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
class PresenterGenerator < Rails::Generators::Base
|
2
|
-
source_root File.expand_path('../templates', __FILE__)
|
3
|
-
argument :presenter_name, :type => :string
|
4
|
-
|
5
|
-
desc "Generates a Presenter Class"
|
6
|
-
def generate_presenter
|
7
|
-
template "presenter.rb", "app/presenters/#{presenter_name.underscore}_presenter.rb"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
1
|
+
class PresenterGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
argument :presenter_name, :type => :string
|
4
|
+
|
5
|
+
desc "Generates a Presenter Class"
|
6
|
+
def generate_presenter
|
7
|
+
template "presenter.rb", "app/presenters/#{presenter_name.underscore}_presenter.rb"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class <%= presenter_name %>Presenter < ClassicPresenter::Base
|
2
|
-
end
|
1
|
+
class <%= presenter_name %>Presenter < ClassicPresenter::Base
|
2
|
+
end
|
@@ -1,35 +1,35 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
describe ClassicPresenter::Base do
|
4
|
-
describe "instance methods" do
|
5
|
-
let(:decorated_object) { decorated_object = [] }
|
6
|
-
let(:context) { double }
|
7
|
-
let(:objects) { {:foo => :bar, :bar => :foo} }
|
8
|
-
|
9
|
-
subject { described_class.new decorated_object, context, objects }
|
10
|
-
|
11
|
-
it "delegates all methods to decorated object" do
|
12
|
-
decorated_object.should_receive(:size)
|
13
|
-
subject.size
|
14
|
-
end
|
15
|
-
|
16
|
-
it "assigns all objects" do
|
17
|
-
subject.foo.should == :bar
|
18
|
-
subject.bar.should == :foo
|
19
|
-
end
|
20
|
-
|
21
|
-
it "assigns the context" do
|
22
|
-
subject.context.should == context
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "class methods" do
|
27
|
-
let(:collection) { [double] }
|
28
|
-
subject { described_class }
|
29
|
-
|
30
|
-
it "maps a collection with a presenter" do
|
31
|
-
decorated_collection = described_class.map collection
|
32
|
-
decorated_collection[0].class.should eq ClassicPresenter::Base
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe ClassicPresenter::Base do
|
4
|
+
describe "instance methods" do
|
5
|
+
let(:decorated_object) { decorated_object = [] }
|
6
|
+
let(:context) { double }
|
7
|
+
let(:objects) { {:foo => :bar, :bar => :foo} }
|
8
|
+
|
9
|
+
subject { described_class.new decorated_object, context, objects }
|
10
|
+
|
11
|
+
it "delegates all methods to decorated object" do
|
12
|
+
decorated_object.should_receive(:size)
|
13
|
+
subject.size
|
14
|
+
end
|
15
|
+
|
16
|
+
it "assigns all objects" do
|
17
|
+
subject.foo.should == :bar
|
18
|
+
subject.bar.should == :foo
|
19
|
+
end
|
20
|
+
|
21
|
+
it "assigns the context" do
|
22
|
+
subject.context.should == context
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "class methods" do
|
27
|
+
let(:collection) { [double] }
|
28
|
+
subject { described_class }
|
29
|
+
|
30
|
+
it "maps a collection with a presenter" do
|
31
|
+
decorated_collection = described_class.map collection
|
32
|
+
decorated_collection[0].class.should eq ClassicPresenter::Base
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
describe ClassicPresenter::Helper do
|
4
|
-
subject { described_class }
|
5
|
-
|
6
|
-
it "yields with a new PresenterClass instance and return it" do
|
7
|
-
presenter_class_as_param = [:value]
|
8
|
-
presenter_class =
|
9
|
-
presenter_class.should_receive(:new).with(:model, described_class, :objects).and_return presenter_class_as_param
|
10
|
-
subject.present(presenter_class, :model, :objects) do |presenter|
|
11
|
-
presenter.pop
|
12
|
-
end.should == []
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe ClassicPresenter::Helper do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
it "yields with a new PresenterClass instance and return it" do
|
7
|
+
presenter_class_as_param = [:value]
|
8
|
+
presenter_class = double
|
9
|
+
presenter_class.should_receive(:new).with(:model, described_class, :objects).and_return presenter_class_as_param
|
10
|
+
subject.present(presenter_class, :model, :objects) do |presenter|
|
11
|
+
presenter.pop
|
12
|
+
end.should == []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
class DummyPresenter < ClassicPresenter::Base
|
4
|
+
def foo
|
5
|
+
target.foo.upcase
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe DummyPresenter do
|
10
|
+
describe "instance methods" do
|
11
|
+
let(:subject) { described_class.new(OpenStruct.new(foo: "bar")) }
|
12
|
+
|
13
|
+
it "calls the presenter method using the target" do
|
14
|
+
subject.foo.should == "BAR"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
$:.unshift File.dirname(__FILE__) + "../lib"
|
2
|
-
require "rubygems"
|
3
|
-
require "delegate"
|
4
|
-
require "classic_presenter/base"
|
5
|
-
require "classic_presenter/helper"
|
6
|
-
require "rspec"
|
7
|
-
|
1
|
+
$:.unshift File.dirname(__FILE__) + "../lib"
|
2
|
+
require "rubygems"
|
3
|
+
require "delegate"
|
4
|
+
require "classic_presenter/base"
|
5
|
+
require "classic_presenter/helper"
|
6
|
+
require "rspec"
|
7
|
+
require "ostruct"
|
8
|
+
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classic_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Rinaldi Fonseca
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: pry
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: A simple Presenter Pattern for Rails Applications
|
@@ -65,32 +60,33 @@ files:
|
|
65
60
|
- lib/generators/templates/presenter.rb
|
66
61
|
- spec/classic_presenter_base_spec.rb
|
67
62
|
- spec/classic_presenter_helper_spec.rb
|
63
|
+
- spec/dummy_presenter_spec.rb
|
68
64
|
- spec/spec_helper.rb
|
69
65
|
homepage: ''
|
70
66
|
licenses: []
|
67
|
+
metadata: {}
|
71
68
|
post_install_message:
|
72
69
|
rdoc_options: []
|
73
70
|
require_paths:
|
74
71
|
- lib
|
75
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
73
|
requirements:
|
78
|
-
- -
|
74
|
+
- - '>='
|
79
75
|
- !ruby/object:Gem::Version
|
80
76
|
version: '0'
|
81
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
78
|
requirements:
|
84
|
-
- -
|
79
|
+
- - '>='
|
85
80
|
- !ruby/object:Gem::Version
|
86
81
|
version: '0'
|
87
82
|
requirements: []
|
88
83
|
rubyforge_project: classic_presenter
|
89
|
-
rubygems_version:
|
84
|
+
rubygems_version: 2.2.1
|
90
85
|
signing_key:
|
91
|
-
specification_version:
|
86
|
+
specification_version: 4
|
92
87
|
summary: A simple Presenter Pattern for Rails Applications
|
93
88
|
test_files:
|
94
89
|
- spec/classic_presenter_base_spec.rb
|
95
90
|
- spec/classic_presenter_helper_spec.rb
|
91
|
+
- spec/dummy_presenter_spec.rb
|
96
92
|
- spec/spec_helper.rb
|