meta_presenter 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/Appraisals +6 -3
- data/Gemfile.lock +16 -1
- data/README.md +3 -1
- data/gemfiles/rails4.gemfile +16 -0
- data/gemfiles/rails5.gemfile +16 -0
- data/lib/meta_presenter/builder.rb +10 -8
- data/lib/meta_presenter/helpers.rb +4 -1
- data/meta_presenter.gemspec +3 -2
- data/spec/meta_presenter/builder_spec.rb +23 -1
- data/spec/support/app/mailers/application_mailer.rb +5 -0
- data/spec/support/app/presenters/mailers/application_presenter.rb +4 -0
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2520562652ee736cdd7cca496683fb093e0b8f6ef5935429504b819feb61991f
|
4
|
+
data.tar.gz: ab969767427ce4242ba5f70b144e277522d81c857b9393596dec839482c2aae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: effeb19171c360f4bb06dcbef0779d60ef321c068a26544a941c33907b4875e5277eceb15dca065608ac4124aeafe00542dd1836ee6b10f3a22cfcb5c07a0d8d
|
7
|
+
data.tar.gz: b4c3959db506ec00f8579e791dd0bf0f76d2955837f2524a256941bc4d2cd6422ca8338464f71a251f21e6f955518047970e9ea57d4cda10451faf16b046df52
|
data/.travis.yml
CHANGED
@@ -11,14 +11,14 @@ rvm:
|
|
11
11
|
- 2.4.0
|
12
12
|
- 2.5.0
|
13
13
|
gemfile:
|
14
|
-
- gemfiles/
|
15
|
-
- gemfiles/
|
14
|
+
- gemfiles/rails4.gemfile
|
15
|
+
- gemfiles/rails5.gemfile
|
16
16
|
matrix:
|
17
17
|
exclude:
|
18
18
|
- rvm: 2.1.0
|
19
|
-
gemfile: gemfiles/
|
19
|
+
gemfile: gemfiles/rails5.gemfile
|
20
20
|
- rvm: 2.2.0
|
21
|
-
gemfile: gemfiles/
|
21
|
+
gemfile: gemfiles/rails5.gemfile
|
22
22
|
script: bundle exec rspec
|
23
23
|
before_install:
|
24
24
|
- gem install bundler -v '< 2'
|
data/Appraisals
CHANGED
@@ -3,15 +3,18 @@
|
|
3
3
|
# gem "actionpack", "3.0.0"
|
4
4
|
#end
|
5
5
|
|
6
|
-
appraise "
|
6
|
+
appraise "rails4" do
|
7
7
|
gem "actionpack", "4.0.0"
|
8
|
+
gem "actionmailer", "4.0.0"
|
8
9
|
end
|
9
10
|
|
10
|
-
appraise "
|
11
|
+
appraise "rails5" do
|
11
12
|
gem "actionpack", "5.0.0"
|
13
|
+
gem "actionmailer", "5.0.0"
|
12
14
|
end
|
13
15
|
|
14
16
|
# TODO: uncomment this once Rails 6 is released on April 30, 2019
|
15
|
-
# appraise "
|
17
|
+
# appraise "rails6" do
|
16
18
|
# gem "actionpack", "6.0.0"
|
19
|
+
# gem "actionmailer", "6.0.0"
|
17
20
|
# end
|
data/Gemfile.lock
CHANGED
@@ -2,11 +2,18 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
meta_presenter (0.1.5)
|
5
|
-
|
5
|
+
actionmailer (>= 4.0)
|
6
|
+
actionpack (>= 4.0)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
actionmailer (5.2.2)
|
12
|
+
actionpack (= 5.2.2)
|
13
|
+
actionview (= 5.2.2)
|
14
|
+
activejob (= 5.2.2)
|
15
|
+
mail (~> 2.5, >= 2.5.4)
|
16
|
+
rails-dom-testing (~> 2.0)
|
10
17
|
actionpack (5.2.2)
|
11
18
|
actionview (= 5.2.2)
|
12
19
|
activesupport (= 5.2.2)
|
@@ -20,6 +27,9 @@ GEM
|
|
20
27
|
erubi (~> 1.4)
|
21
28
|
rails-dom-testing (~> 2.0)
|
22
29
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
30
|
+
activejob (5.2.2)
|
31
|
+
activesupport (= 5.2.2)
|
32
|
+
globalid (>= 0.3.6)
|
23
33
|
activesupport (5.2.2)
|
24
34
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
25
35
|
i18n (>= 0.7, < 2)
|
@@ -42,13 +52,18 @@ GEM
|
|
42
52
|
diff-lcs (1.3)
|
43
53
|
docile (1.3.1)
|
44
54
|
erubi (1.8.0)
|
55
|
+
globalid (0.4.2)
|
56
|
+
activesupport (>= 4.2.0)
|
45
57
|
i18n (1.5.2)
|
46
58
|
concurrent-ruby (~> 1.0)
|
47
59
|
json (2.1.0)
|
48
60
|
loofah (2.2.3)
|
49
61
|
crass (~> 1.0.2)
|
50
62
|
nokogiri (>= 1.5.9)
|
63
|
+
mail (2.7.1)
|
64
|
+
mini_mime (>= 0.1.1)
|
51
65
|
method_source (0.9.2)
|
66
|
+
mini_mime (1.0.1)
|
52
67
|
mini_portile2 (2.4.0)
|
53
68
|
minitest (5.11.3)
|
54
69
|
nokogiri (1.10.1)
|
data/README.md
CHANGED
@@ -203,8 +203,10 @@ MetaPresenter supports Ruby >= 2.1 and ActionPack >= 4.0. If you'd like to help
|
|
203
203
|
## Specs
|
204
204
|
To run the specs for the currently running Ruby version, run `bundle install` and then `bundle exec rspec`. To run specs for every supported version of ActionPack, run `bundle exec appraisal install` and then `bundle exec appraisal rspec`.
|
205
205
|
|
206
|
+
## Gem release
|
207
|
+
Make sure the specs pass, bump the version number in meta_presenter.gemspec, build the gem with `gem build meta_presenter.gemspec`. Then commit changes and tag the commit with the current release number with `git tag -a "vVersionNumberHere" -m "vVersionNumberHere"`. Push the commit with `git push`, then push the tags with `git push origin --tags`. Finally, push the gem with `gem push meta_presenter-version-number-here.gem`.
|
208
|
+
|
206
209
|
## TODO
|
207
|
-
* tests for ActionMailer support
|
208
210
|
* optional `rake meta_presenter:install` that generates the scaffolding for you. Or, you can manually create the files you want.
|
209
211
|
* add support for layout-level presenters
|
210
212
|
* add Rails 6 support once it comes out (hopefully just have to add a gemfiles/actionpack6.gemfile and it will run with the Appraisal suite)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "actionpack", "4.0.0"
|
6
|
+
gem "actionmailer", "4.0.0"
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "pry"
|
10
|
+
gem "rspec"
|
11
|
+
gem "builder"
|
12
|
+
gem "rb-readline"
|
13
|
+
gem "coveralls"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "actionpack", "5.0.0"
|
6
|
+
gem "actionmailer", "5.0.0"
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "pry"
|
10
|
+
gem "rspec"
|
11
|
+
gem "builder"
|
12
|
+
gem "rb-readline"
|
13
|
+
gem "coveralls"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
@@ -31,10 +31,10 @@ module MetaPresenter
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
class
|
34
|
+
class InvalidControllerError < NameError
|
35
35
|
# Create a new error
|
36
|
-
def initialize(controller
|
37
|
-
super("
|
36
|
+
def initialize(controller)
|
37
|
+
super("You tried to present a #{controller.class.name} class, but only a Rails controller or mailer can be presented")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -49,10 +49,6 @@ module MetaPresenter
|
|
49
49
|
break if !klass.nil?
|
50
50
|
end
|
51
51
|
|
52
|
-
if klass.nil?
|
53
|
-
raise NoPresenterClassDefinedError.new(controller, action_name)
|
54
|
-
end
|
55
|
-
|
56
52
|
klass
|
57
53
|
end
|
58
54
|
|
@@ -63,7 +59,13 @@ module MetaPresenter
|
|
63
59
|
private
|
64
60
|
def all_ancestors
|
65
61
|
controller.class.ancestors.select do |ancestor|
|
66
|
-
|
62
|
+
if controller.class <= ActionController::Base
|
63
|
+
ancestor <= ActionController::Base
|
64
|
+
elsif controller.class <= ActionMailer::Base
|
65
|
+
ancestor <= ActionMailer::Base
|
66
|
+
else
|
67
|
+
raise InvalidControllerError.new(controller)
|
68
|
+
end
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'meta_presenter/builder'
|
2
2
|
require 'active_support/concern'
|
3
|
+
require 'active_support/rescuable'
|
3
4
|
|
4
5
|
module MetaPresenter
|
5
6
|
# Including this module in your controller will give
|
@@ -34,7 +35,9 @@ module MetaPresenter
|
|
34
35
|
@presenter ||= begin
|
35
36
|
controller = self
|
36
37
|
klass = MetaPresenter::Builder.new(controller, action_name).presenter_class
|
37
|
-
|
38
|
+
if klass.nil?
|
39
|
+
raise PresenterClassNotFoundError.new(controller, action_name)
|
40
|
+
end
|
38
41
|
klass.new(controller)
|
39
42
|
end
|
40
43
|
end
|
data/meta_presenter.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'meta_presenter'
|
5
|
-
s.version = '0.1.
|
5
|
+
s.version = '0.1.6'
|
6
6
|
s.platform = Gem::Platform::RUBY
|
7
7
|
s.authors = ['szTheory']
|
8
8
|
s.description = %q{Presenter pattern in your Rails controllers and actions}
|
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
s.required_ruby_version = '>= 2.1.0'
|
21
21
|
|
22
|
-
s.add_dependency 'actionpack', '>=
|
22
|
+
s.add_dependency 'actionpack', '>= 4.0'
|
23
|
+
s.add_dependency 'actionmailer', '>= 4.0'
|
23
24
|
|
24
25
|
s.add_development_dependency 'rspec'
|
25
26
|
s.add_development_dependency 'bundler'
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
# require 'ostruct'
|
2
3
|
|
3
4
|
describe MetaPresenter::Builder do
|
4
5
|
let(:controller_class) { ApplicationController }
|
5
|
-
let(:controller) { controller_class.new }
|
6
|
+
let(:controller) { controller_class.send(:new) }
|
6
7
|
let(:action_name) { 'logs' }
|
7
8
|
let(:object) { described_class.new(controller, action_name) }
|
8
9
|
|
@@ -44,6 +45,27 @@ describe MetaPresenter::Builder do
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
48
|
+
context "neither a controller nor a mailer" do
|
49
|
+
let(:controller_class) { OpenStruct }
|
50
|
+
|
51
|
+
before do
|
52
|
+
expect(controller_class < ActionController::Base).to_not be true
|
53
|
+
expect(controller_class < ActionMailer::Base).to_not be true
|
54
|
+
end
|
55
|
+
|
56
|
+
it { expect { subject }.to raise_error(MetaPresenter::Builder::InvalidControllerError) }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "mailer" do
|
60
|
+
let(:controller_class) { ApplicationMailer }
|
61
|
+
|
62
|
+
before do
|
63
|
+
expect(controller_class < ActionMailer::Base).to be true
|
64
|
+
end
|
65
|
+
|
66
|
+
it { is_expected.to be Mailers::ApplicationPresenter }
|
67
|
+
end
|
68
|
+
|
47
69
|
context "subclass of ApplicationController" do
|
48
70
|
let(:controller_class) { PagesController }
|
49
71
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meta_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- szTheory
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionmailer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +153,8 @@ files:
|
|
139
153
|
- gemfiles/.bundle/config
|
140
154
|
- gemfiles/actionpack4.gemfile
|
141
155
|
- gemfiles/actionpack5.gemfile
|
156
|
+
- gemfiles/rails4.gemfile
|
157
|
+
- gemfiles/rails5.gemfile
|
142
158
|
- lib/meta_presenter.rb
|
143
159
|
- lib/meta_presenter/base.rb
|
144
160
|
- lib/meta_presenter/base/delegate_all_to.rb
|
@@ -154,9 +170,11 @@ files:
|
|
154
170
|
- spec/support/app/controllers/application_controller.rb
|
155
171
|
- spec/support/app/controllers/pages_controller.rb
|
156
172
|
- spec/support/app/controllers/without_presenter_controller.rb
|
173
|
+
- spec/support/app/mailers/application_mailer.rb
|
157
174
|
- spec/support/app/presenters/admin/dashboard/inbox_presenter.rb
|
158
175
|
- spec/support/app/presenters/admin/dashboard_presenter.rb
|
159
176
|
- spec/support/app/presenters/application_presenter.rb
|
177
|
+
- spec/support/app/presenters/mailers/application_presenter.rb
|
160
178
|
- spec/support/app/presenters/pages/logs_presenter.rb
|
161
179
|
- spec/support/app/presenters/pages/only_file_exists_presenter.rb
|
162
180
|
- spec/support/app/presenters/pages_presenter.rb
|
@@ -198,9 +216,11 @@ test_files:
|
|
198
216
|
- spec/support/app/controllers/application_controller.rb
|
199
217
|
- spec/support/app/controllers/pages_controller.rb
|
200
218
|
- spec/support/app/controllers/without_presenter_controller.rb
|
219
|
+
- spec/support/app/mailers/application_mailer.rb
|
201
220
|
- spec/support/app/presenters/admin/dashboard/inbox_presenter.rb
|
202
221
|
- spec/support/app/presenters/admin/dashboard_presenter.rb
|
203
222
|
- spec/support/app/presenters/application_presenter.rb
|
223
|
+
- spec/support/app/presenters/mailers/application_presenter.rb
|
204
224
|
- spec/support/app/presenters/pages/logs_presenter.rb
|
205
225
|
- spec/support/app/presenters/pages/only_file_exists_presenter.rb
|
206
226
|
- spec/support/app/presenters/pages_presenter.rb
|