presenter_rails 2.0.0 → 3.0.0

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
- SHA1:
3
- metadata.gz: ad881d965883dd21b21b96fca07691befd7aaa50
4
- data.tar.gz: bbd8f56f09035195e9b469733f98188b281e8c37
2
+ SHA256:
3
+ metadata.gz: a355a092de54795f9dfe502bb5b0f261232d0596b1062063377e223282e77ac3
4
+ data.tar.gz: 167f0bdfc3541a90df1a481ed39c0d40c6259472f1b397acf90e7c6c1c99be3d
5
5
  SHA512:
6
- metadata.gz: d0540e2d1c5e94a3aacb7ca87db48ec09f67c8c06bca8685e3f6bb501c49aec9e7c08b4599fa1a8882fe2c97f27b598f05a90ab25b29e4f46430c89c28d4a853
7
- data.tar.gz: cb5fd596bc8178cc99362e555d0c3039b3448786279a702791d332fbf43be36f6517b4bcf1b5a7d3c6fa5b6719073904961b08ebbb60432de43286ce483df6fb
6
+ metadata.gz: 860615c6538cffd6b4b1cbdf1f30cb3834a65e4b9d0058b46b267d720f81b9143d8610013fbb2a72f6778e5b8a529b6659f34a55fad4a5fea3a427314c4f7cdb
7
+ data.tar.gz: 66fb24a6bad6b1cfd78226fd5dd3c3fba992322b1e32a227be33c88b97c8fbff91edf08674b25e6c7ad6f514415f5e7d6cf979c3e0ba55775de4296599929d3e
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## PresenterRails 3.0.0 (2021-02-24) ##
2
+
3
+ * Remove `ruby_version` restriction from gemspec to allow usage in Ruby 3.0.
4
+ * Remove additional Controller module.
5
+
6
+ ## PresenterRails 2.0.0 (2017-04-01) ##
7
+
8
+ * Now every call to `present` must pass a block, and defines a single method.
9
+ * PresenterRails is auto-included in mailers as well.
10
+ * Presenter methods are no longer assignable since the need does not come up in practice (`pakiderm` used to provide the feature).
11
+ * Dropped `pakiderm` as a dependency since memoization is now simpler.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Presenter [![Gem Version](https://badge.fury.io/rb/presenter_rails.svg)](http://badge.fury.io/rb/presenter_rails) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ElMassimo/presenter_rails/blob/master/LICENSE.txt)
1
+ Presenter [![Gem Version](https://badge.fury.io/rb/presenter_rails.svg)](https://rubygems.org/gems/presenter_rails) [![Build Status](https://github.com/ElMassimo/presenter_rails/workflows/build/badge.svg)](https://github.com/ElMassimo/presenter_rails/actions) [![Test Coverage](https://codeclimate.com/github/ElMassimo/presenter_rails/badges/coverage.svg)](https://codeclimate.com/github/ElMassimo/presenter_rails) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ElMassimo/presenter_rails/blob/master/LICENSE.txt)
2
2
  =====================
3
3
 
4
4
  Presenter helps you expose view models to your views in a convenient way, while
@@ -32,7 +32,9 @@ The method is also available in the controller, with a `_presenter` suffix:
32
32
  # app/controllers/people_controller.rb
33
33
  class PeopleController < ApplicationController
34
34
 
35
- ...
35
+ present(:person) {
36
+ PersonDecorator.decorate(person)
37
+ }
36
38
 
37
39
  def update
38
40
  person.update(attrs)
@@ -47,7 +49,7 @@ The method is also available in the controller, with a `_presenter` suffix:
47
49
  ## Background
48
50
  Presenter attempts to simplify the exposure of variables to the views. It doesn't really care
49
51
  about what you are exposing, although it's specially useful to implement [two-step views](http://martinfowler.com/eaaCatalog/twoStepView.html) while using
50
- [draper](https://github.com/drapergem/draper) in combination with [resourcerer](https://github.com/ElMassimo/resourcerer).
52
+ [view models](https://github.com/drapergem/draper) in combination with [resourcerer](https://github.com/ElMassimo/resourcerer).
51
53
 
52
54
  ### How it works
53
55
 
@@ -59,36 +61,8 @@ After that, it creates a helper method for your views, which calls the `"#{name}
59
61
  Each presenter method is memoized, so the method is called only once and your views get the same instance every time. The block is evaluated only if the method is called.
60
62
 
61
63
  #### Corolary
62
- Since the helper methods defined are only available for the view, you can define methods with the same name in your controller :smiley:.
63
-
64
- License
65
- --------
66
-
67
- Copyright (c) 2014 Máximo Mussini
68
-
69
- MIT License
70
-
71
- Permission is hereby granted, free of charge, to any person obtaining
72
- a copy of this software and associated documentation files (the
73
- "Software"), to deal in the Software without restriction, including
74
- without limitation the rights to use, copy, modify, merge, publish,
75
- distribute, sublicense, and/or sell copies of the Software, and to
76
- permit persons to whom the Software is furnished to do so, subject to
77
- the following conditions:
78
-
79
- The above copyright notice and this permission notice shall be
80
- included in all copies or substantial portions of the Software.
81
-
82
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
83
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
84
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
85
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
86
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
87
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
88
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
89
-
64
+ Since the helper methods defined are only available for the view, you can define methods with the same name in your controller :smiley:
90
65
 
91
66
  Credits
92
67
  --------
93
- Presenter was crafted to use in combination with [resourcerer](https://github.com/ElMassimo/resourcerer) and
94
- [draper](https://github.com/drapergem/draper).
68
+ Presenter was crafted to use in combination with [resourcerer](https://github.com/ElMassimo/resourcerer).
@@ -2,7 +2,29 @@ require "presenter_rails/version"
2
2
  require "active_support/all"
3
3
 
4
4
  module PresenterRails
5
- autoload :Controller, "presenter_rails/controller"
5
+ # Public: Defines a method and makes it available to the view context
6
+ # under the specified name as a memoized variable.
7
+ #
8
+ # name - The name of the method as called from the view context.
9
+ # block - Executed once if (and only if) the method is called.
10
+ #
11
+ # Returns nothing.
12
+ def present(name, &block)
13
+ presenter_method = PresenterRails.method_name_for(name)
14
+ ivar = PresenterRails.ivar_for(name)
15
+
16
+ private define_method(presenter_method) {
17
+ if instance_variable_defined?(ivar)
18
+ instance_variable_get(ivar)
19
+ else
20
+ instance_variable_set(ivar, instance_exec(&block))
21
+ end
22
+ }
23
+
24
+ helper Module.new {
25
+ define_method(name) { controller.send(presenter_method) }
26
+ }
27
+ end
6
28
 
7
29
  # Internal: Name of the presenter method as defined in the controller.
8
30
  def self.method_name_for(name)
@@ -15,10 +37,10 @@ module PresenterRails
15
37
  end
16
38
 
17
39
  ActiveSupport.on_load :action_controller do
18
- extend Controller
40
+ extend PresenterRails
19
41
  end
20
42
 
21
43
  ActiveSupport.on_load :action_mailer do
22
- extend Controller
44
+ extend PresenterRails
23
45
  end
24
46
  end
@@ -1,3 +1,3 @@
1
1
  module PresenterRails
2
- VERSION = "2.0.0"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
  require "rspec/rails"
3
3
 
4
- RSpec.describe PresenterRails::Controller do
4
+ RSpec.describe PresenterRails do
5
5
  class Thing; end
6
6
  class DifferentThing; end
7
7
 
@@ -14,7 +14,7 @@ RSpec.describe PresenterRails::Controller do
14
14
  end
15
15
 
16
16
  class BaseController
17
- extend PresenterRails::Controller
17
+ extend PresenterRails
18
18
 
19
19
  def self.helper(helper_module)
20
20
  @helper_modules ||= []
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "simplecov"
2
+ SimpleCov.start { add_filter '/spec/' }
3
+
1
4
  require "presenter_rails"
2
5
  require "rspec/given"
3
- require "pry-byebug"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: presenter_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Máximo Mussini
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-02 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -25,33 +25,47 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: railties
28
+ name: actionmailer
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '4.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '4.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: actionmailer
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.18'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "<"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.18'
55
+ - !ruby/object:Gem::Dependency
56
+ name: railties
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: '4.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: '4.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec-given
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -89,9 +103,9 @@ extensions: []
89
103
  extra_rdoc_files:
90
104
  - README.md
91
105
  files:
106
+ - CHANGELOG.md
92
107
  - README.md
93
108
  - lib/presenter_rails.rb
94
- - lib/presenter_rails/controller.rb
95
109
  - lib/presenter_rails/version.rb
96
110
  - spec/features/birds_controller_spec.rb
97
111
  - spec/features/birds_mailer_spec.rb
@@ -102,13 +116,13 @@ homepage: https://github.com/ElMassimo/presenter_rails
102
116
  licenses:
103
117
  - MIT
104
118
  metadata: {}
105
- post_install_message:
119
+ post_install_message:
106
120
  rdoc_options: []
107
121
  require_paths:
108
122
  - lib
109
123
  required_ruby_version: !ruby/object:Gem::Requirement
110
124
  requirements:
111
- - - "~>"
125
+ - - ">="
112
126
  - !ruby/object:Gem::Version
113
127
  version: '2.0'
114
128
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -117,11 +131,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
131
  - !ruby/object:Gem::Version
118
132
  version: '0'
119
133
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.5.1
122
- signing_key:
134
+ rubygems_version: 3.2.3
135
+ signing_key:
123
136
  specification_version: 4
124
- summary: ViewModels had a baby with helper_method
137
+ summary: Expose your view models without using instance variables.
125
138
  test_files:
126
139
  - spec/features/birds_controller_spec.rb
127
140
  - spec/features/birds_mailer_spec.rb
@@ -1,26 +0,0 @@
1
- module PresenterRails
2
- module Controller
3
- # Public: Defines a method and makes it available to the view context
4
- # under the specified name as a memoized variable.
5
- #
6
- # name - The name of the method as called from the view context.
7
- # block - Executed once if (and only if) the method is called.
8
- #
9
- # Returns nothing.
10
- def present(name, &block)
11
- presenter_method = PresenterRails.method_name_for(name)
12
- ivar = PresenterRails.ivar_for(name)
13
-
14
- private define_method(presenter_method) {
15
- unless instance_variable_defined?(ivar)
16
- instance_variable_set(ivar, instance_exec(&block))
17
- end
18
- instance_variable_get(ivar)
19
- }
20
-
21
- helper Module.new {
22
- define_method(name) { controller.send(presenter_method) }
23
- }
24
- end
25
- end
26
- end