decent_decoration-ruby3 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c34e141b33d66f396cbf7973cbe8259c4c96fa6b8d4375ebb5aac63bc639dcde
4
+ data.tar.gz: 8126ecb27b34c7d513e3a0a484b8d3044966bba4a874a7a13be9dbe8b704da29
5
+ SHA512:
6
+ metadata.gz: 70c289a9d9450f2baf493d160168597e5556a2c6a3c65f2184fbb6c917a6b80d4e5dcf1b6a6108452c8b34471191f5b8d7a31b675ed5f6a5d440c5b68ebed1cb
7
+ data.tar.gz: 547e34277283c702834e47335a1fb1452ab401d4855e6b7f0035f8892b44f0e07736aa4c3d04bc8a75e64b9b6b6f5b1839ad9853579226747242358839cdfdef
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ - 2.3.0
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - pewniak747@gmail.com
9
+ - bartosz.kopinski@netguru.pl
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## v0.1.0
4
+
5
+ * make compatible with decent_exposure 3.0
6
+ * drop Ruby 1.9.3 support
7
+
8
+ ## v0.0.6
9
+
10
+ * fixed `decent_exposure` dependency [@madsheep]
11
+
12
+ ## v0.0.5
13
+
14
+ * relaxed actionpack dependency allowing usage with rails 4
15
+ * fixed deprecation warnings in specs
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in decent_decorate.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,217 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ decent_decoration (0.1.0)
5
+ decent_exposure (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.1.7.6)
11
+ actionpack (= 6.1.7.6)
12
+ activesupport (= 6.1.7.6)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.1.7.6)
16
+ actionpack (= 6.1.7.6)
17
+ activejob (= 6.1.7.6)
18
+ activerecord (= 6.1.7.6)
19
+ activestorage (= 6.1.7.6)
20
+ activesupport (= 6.1.7.6)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.1.7.6)
23
+ actionpack (= 6.1.7.6)
24
+ actionview (= 6.1.7.6)
25
+ activejob (= 6.1.7.6)
26
+ activesupport (= 6.1.7.6)
27
+ mail (~> 2.5, >= 2.5.4)
28
+ rails-dom-testing (~> 2.0)
29
+ actionpack (6.1.7.6)
30
+ actionview (= 6.1.7.6)
31
+ activesupport (= 6.1.7.6)
32
+ rack (~> 2.0, >= 2.0.9)
33
+ rack-test (>= 0.6.3)
34
+ rails-dom-testing (~> 2.0)
35
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
+ actiontext (6.1.7.6)
37
+ actionpack (= 6.1.7.6)
38
+ activerecord (= 6.1.7.6)
39
+ activestorage (= 6.1.7.6)
40
+ activesupport (= 6.1.7.6)
41
+ nokogiri (>= 1.8.5)
42
+ actionview (6.1.7.6)
43
+ activesupport (= 6.1.7.6)
44
+ builder (~> 3.1)
45
+ erubi (~> 1.4)
46
+ rails-dom-testing (~> 2.0)
47
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
+ activejob (6.1.7.6)
49
+ activesupport (= 6.1.7.6)
50
+ globalid (>= 0.3.6)
51
+ activemodel (6.1.7.6)
52
+ activesupport (= 6.1.7.6)
53
+ activemodel-serializers-xml (1.0.2)
54
+ activemodel (> 5.x)
55
+ activesupport (> 5.x)
56
+ builder (~> 3.1)
57
+ activerecord (6.1.7.6)
58
+ activemodel (= 6.1.7.6)
59
+ activesupport (= 6.1.7.6)
60
+ activestorage (6.1.7.6)
61
+ actionpack (= 6.1.7.6)
62
+ activejob (= 6.1.7.6)
63
+ activerecord (= 6.1.7.6)
64
+ activesupport (= 6.1.7.6)
65
+ marcel (~> 1.0)
66
+ mini_mime (>= 1.1.0)
67
+ activesupport (6.1.7.6)
68
+ concurrent-ruby (~> 1.0, >= 1.0.2)
69
+ i18n (>= 1.6, < 2)
70
+ minitest (>= 5.1)
71
+ tzinfo (~> 2.0)
72
+ zeitwerk (~> 2.3)
73
+ builder (3.2.4)
74
+ concurrent-ruby (1.2.2)
75
+ coveralls (0.8.23)
76
+ json (>= 1.8, < 3)
77
+ simplecov (~> 0.16.1)
78
+ term-ansicolor (~> 1.3)
79
+ thor (>= 0.19.4, < 2.0)
80
+ tins (~> 1.6)
81
+ crass (1.0.6)
82
+ date (3.3.4)
83
+ decent_exposure (3.0.4)
84
+ activesupport (>= 4.0)
85
+ diff-lcs (1.5.0)
86
+ docile (1.4.0)
87
+ draper (4.0.2)
88
+ actionpack (>= 5.0)
89
+ activemodel (>= 5.0)
90
+ activemodel-serializers-xml (>= 1.0)
91
+ activesupport (>= 5.0)
92
+ request_store (>= 1.0)
93
+ ruby2_keywords
94
+ erubi (1.12.0)
95
+ globalid (1.2.1)
96
+ activesupport (>= 6.1)
97
+ i18n (1.14.1)
98
+ concurrent-ruby (~> 1.0)
99
+ json (2.6.3)
100
+ loofah (2.21.4)
101
+ crass (~> 1.0.2)
102
+ nokogiri (>= 1.12.0)
103
+ mail (2.8.1)
104
+ mini_mime (>= 0.1.1)
105
+ net-imap
106
+ net-pop
107
+ net-smtp
108
+ marcel (1.0.2)
109
+ method_source (1.0.0)
110
+ mini_mime (1.1.5)
111
+ mini_portile2 (2.8.5)
112
+ minitest (5.20.0)
113
+ net-imap (0.4.4)
114
+ date
115
+ net-protocol
116
+ net-pop (0.1.2)
117
+ net-protocol
118
+ net-protocol (0.2.2)
119
+ timeout
120
+ net-smtp (0.4.0)
121
+ net-protocol
122
+ nio4r (2.5.9)
123
+ nokogiri (1.15.4)
124
+ mini_portile2 (~> 2.8.2)
125
+ racc (~> 1.4)
126
+ racc (1.7.3)
127
+ rack (2.2.8)
128
+ rack-test (2.1.0)
129
+ rack (>= 1.3)
130
+ rails (6.1.7.6)
131
+ actioncable (= 6.1.7.6)
132
+ actionmailbox (= 6.1.7.6)
133
+ actionmailer (= 6.1.7.6)
134
+ actionpack (= 6.1.7.6)
135
+ actiontext (= 6.1.7.6)
136
+ actionview (= 6.1.7.6)
137
+ activejob (= 6.1.7.6)
138
+ activemodel (= 6.1.7.6)
139
+ activerecord (= 6.1.7.6)
140
+ activestorage (= 6.1.7.6)
141
+ activesupport (= 6.1.7.6)
142
+ bundler (>= 1.15.0)
143
+ railties (= 6.1.7.6)
144
+ sprockets-rails (>= 2.0.0)
145
+ rails-dom-testing (2.2.0)
146
+ activesupport (>= 5.0.0)
147
+ minitest
148
+ nokogiri (>= 1.6)
149
+ rails-html-sanitizer (1.6.0)
150
+ loofah (~> 2.21)
151
+ nokogiri (~> 1.14)
152
+ railties (6.1.7.6)
153
+ actionpack (= 6.1.7.6)
154
+ activesupport (= 6.1.7.6)
155
+ method_source
156
+ rake (>= 12.2)
157
+ thor (~> 1.0)
158
+ rake (13.1.0)
159
+ request_store (1.5.1)
160
+ rack (>= 1.4)
161
+ rspec-core (3.12.2)
162
+ rspec-support (~> 3.12.0)
163
+ rspec-expectations (3.12.3)
164
+ diff-lcs (>= 1.2.0, < 2.0)
165
+ rspec-support (~> 3.12.0)
166
+ rspec-mocks (3.12.6)
167
+ diff-lcs (>= 1.2.0, < 2.0)
168
+ rspec-support (~> 3.12.0)
169
+ rspec-rails (6.0.3)
170
+ actionpack (>= 6.1)
171
+ activesupport (>= 6.1)
172
+ railties (>= 6.1)
173
+ rspec-core (~> 3.12)
174
+ rspec-expectations (~> 3.12)
175
+ rspec-mocks (~> 3.12)
176
+ rspec-support (~> 3.12)
177
+ rspec-support (3.12.1)
178
+ ruby2_keywords (0.0.5)
179
+ simplecov (0.16.1)
180
+ docile (~> 1.1)
181
+ json (>= 1.8, < 3)
182
+ simplecov-html (~> 0.10.0)
183
+ simplecov-html (0.10.2)
184
+ sprockets (4.2.1)
185
+ concurrent-ruby (~> 1.0)
186
+ rack (>= 2.2.4, < 4)
187
+ sprockets-rails (3.4.2)
188
+ actionpack (>= 5.2)
189
+ activesupport (>= 5.2)
190
+ sprockets (>= 3.0.0)
191
+ sync (0.5.0)
192
+ term-ansicolor (1.7.1)
193
+ tins (~> 1.0)
194
+ thor (1.3.0)
195
+ timeout (0.4.1)
196
+ tins (1.32.1)
197
+ sync
198
+ tzinfo (2.0.6)
199
+ concurrent-ruby (~> 1.0)
200
+ websocket-driver (0.7.6)
201
+ websocket-extensions (>= 0.1.0)
202
+ websocket-extensions (0.1.5)
203
+ zeitwerk (2.6.12)
204
+
205
+ PLATFORMS
206
+ ruby
207
+
208
+ DEPENDENCIES
209
+ activesupport (~> 6.0)
210
+ coveralls
211
+ decent_decoration!
212
+ draper (~> 4.0)
213
+ rails (~> 6.0)
214
+ rspec-rails (~> 6.0)
215
+
216
+ BUNDLED WITH
217
+ 2.4.22
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012-2014 netguru
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # decent_decoration
2
+ [![Build Status](https://secure.travis-ci.org/netguru/decent_decoration.png?branch=master)](http://travis-ci.org/netguru/decent_decoration)
3
+ [![Code Climate](https://codeclimate.com/github/netguru/decent_decoration.png)](https://codeclimate.com/github/netguru/decent_decoration)
4
+ [![Coverage Status](https://coveralls.io/repos/netguru/decent_decoration/badge.png?branch=master)](https://coveralls.io/r/netguru/decent_decoration)
5
+ [![Gem Version](https://badge.fury.io/rb/decent_decoration.png)](http://badge.fury.io/rb/decent_decoration)
6
+
7
+ decent_decoration allows you to use excellent [decent_exposure 3.0][decent_exposure] gem with decorators.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```
14
+ gem 'decent_decoration', '~> 0.1.0'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```
20
+ $ bundle
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ``` ruby
26
+ # app/controllers/conferences_controller.rb
27
+ # with decent_exposure
28
+ class ConferencesController < ApplicationController
29
+ expose(:conference) { ConferenceDecorator.new(build_conference) }
30
+
31
+ private
32
+
33
+ def build_conference
34
+ # create new conference or fetch existing one
35
+ end
36
+ end
37
+
38
+ # with decent_decoration
39
+ class ConferencesController < ApplicationController
40
+ expose_decorated(:conference)
41
+ end
42
+ ```
43
+
44
+ decent_decoration makes decorated objects accessible in views. They remain undecorated in your controllers.
45
+
46
+ Define a decorator explicitly:
47
+
48
+ ``` ruby
49
+ # app/controllers/conferences_controller.rb
50
+ class ConferencesController < ApplicationController
51
+ expose_decorated(:conference, decorator: SponsoredConferenceDecorator)
52
+ end
53
+ ```
54
+
55
+ decent_decoration detect automatically if you want to decorate a collection. To circumvent this pass collection: true/false
56
+
57
+ ``` ruby
58
+ # app/controllers/conferences_controller.rb
59
+ class ConferencesController < ApplicationController
60
+ expose_decorated(:conferences, collection: false)
61
+ end
62
+ ```
63
+
64
+ decent_decoration supports most of the awesome [decent_exposure api][decent_exposure_api]. Read [more about it!][decent_exposure_api]
65
+
66
+ ``` ruby
67
+ # app/controllers/attendees_controller.rb
68
+ class AttendeesController < ApplicationController
69
+ expose_decorated(:conference)
70
+ expose_decorated(:attendees, scope: :conference)
71
+ end
72
+ ```
73
+
74
+ You can use any decorator mechanism as long as `ConferenceDecorator` responds to `#decorate` or `#new`. Try [draper][draper].
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create new Pull Request
83
+
84
+ [decent_exposure]: https://github.com/voxdolo/decent_exposure
85
+ [decent_exposure_api]: https://github.com/voxdolo/decent_exposure#usage
86
+ [draper]: https://github.com/drapergem/draper
87
+
88
+ Copyright © 2012–2014 [netguru](https://netguru.co). See LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'decent_decoration/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "decent_decoration-ruby3"
8
+ gem.version = DecentDecoration::VERSION
9
+ gem.authors = ["Tomasz Pewiński"]
10
+ gem.email = ["pewniak747@gmail.com"]
11
+ gem.description = %q{Use decent_exposure with decorators (e.g. Draper)}
12
+ gem.summary = %q{Use decent_exposure with decorators (e.g. Draper)}
13
+ gem.homepage = "https://github.com/netguru/decent_decoration"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.required_ruby_version = ">= 3.0"
21
+
22
+ gem.add_runtime_dependency 'decent_exposure', '~> 3.0'
23
+
24
+ gem.add_development_dependency 'rspec-rails', "~> 6.0"
25
+ gem.add_development_dependency 'rails', '~> 6.0'
26
+ gem.add_development_dependency 'activesupport', '~> 6.0'
27
+ gem.add_development_dependency 'draper', '~> 4.0'
28
+ end
@@ -0,0 +1,80 @@
1
+ module DecentDecoration
2
+ class Decoration
3
+ attr_accessor :name, :original_options
4
+ private :original_options
5
+
6
+ def initialize(name, options = {})
7
+ self.name = name
8
+ self.original_options = options
9
+ end
10
+
11
+ def decorated_name
12
+ "decorated_#{name}".to_sym
13
+ end
14
+
15
+ def options
16
+ original_options.except(:decorator, :collection)
17
+ end
18
+
19
+ def decorator_class
20
+ original_options.fetch(:decorator) { infer_decorator_class }
21
+ end
22
+
23
+ def decorate_method
24
+ if decorate_collection? && decorator_class.respond_to?(:decorate_collection)
25
+ :decorate_collection
26
+ elsif decorator_class.respond_to?(:decorate)
27
+ :decorate
28
+ else
29
+ :new
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def infer_decorator_class
36
+ "#{name.to_s.classify}Decorator".constantize
37
+ end
38
+
39
+ def decorate_collection?
40
+ (plural_name? && force_collection != false) || force_collection == true
41
+ end
42
+
43
+ def force_collection
44
+ original_options[:collection]
45
+ end
46
+
47
+ def plural_name?
48
+ plural_name == name && plural_name != singular_name
49
+ end
50
+
51
+ def plural_name
52
+ name.to_s.pluralize.to_sym
53
+ end
54
+
55
+ def singular_name
56
+ name.to_s.singularize.to_sym
57
+ end
58
+ end
59
+
60
+ module ControllerMethods
61
+ def expose_decorated(name, *args, &block)
62
+ options = args.extract_options!
63
+ decoration = Decoration.new(name, options)
64
+
65
+ decorator_class = decoration.decorator_class
66
+ decorate_method = decoration.decorate_method
67
+ decorated_name = decoration.decorated_name
68
+ options = decoration.options
69
+
70
+ expose(name, *args, **options, &block)
71
+ expose(decorated_name) { decorator_class.public_send(decorate_method, public_send(name)) }
72
+
73
+ helper Module.new do
74
+ define_method(name) do
75
+ public_send(decorated_name)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ module DecentDecoration
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "decent_decoration/decorate"
2
+ require "decent_decoration/version"
3
+
4
+ ActiveSupport.on_load(:action_controller) do
5
+ extend DecentDecoration::ControllerMethods
6
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe DecentDecoration::Decoration do
4
+ let(:klass) { DecentDecoration::Decoration }
5
+
6
+ it "should be initialized with name" do
7
+ subject = klass.new(:conference)
8
+ expect(subject.name).to eq :conference
9
+ end
10
+
11
+ it "should be initialized with options" do
12
+ subject = klass.new(:conference, { model: :conference })
13
+ expect(subject.options).to eq({ model: :conference })
14
+ end
15
+
16
+ describe "#decorated_name" do
17
+ it "should consist of name prepended by decorated" do
18
+ expect(klass.new(:conference).decorated_name).to eq :decorated_conference
19
+ end
20
+ end
21
+
22
+ describe "#decorator_class" do
23
+ it "should infer the class from name" do
24
+ expect(klass.new(:conference).decorator_class).to eq ConferenceDecorator
25
+ end
26
+
27
+ it "should use :decorator if passed" do
28
+ expect(klass.new(:conference, decorator: AttendeeDecorator).decorator_class).to eq AttendeeDecorator
29
+ end
30
+ end
31
+
32
+ describe "#decorate_method" do
33
+ describe "when name is plural" do
34
+ subject { klass.new(:conferences, decorator: decorator) }
35
+ let(:decorator) { double }
36
+
37
+ it "should be :decorate_collection if decorator supports it" do
38
+ allow(decorator).to receive(:decorate_collection)
39
+ expect(subject.decorate_method).to eq :decorate_collection
40
+ end
41
+
42
+ it "should be :decorate if decorator does not support :decorate_collection and supports :decorate" do
43
+ allow(decorator).to receive(:decorate)
44
+ expect(subject.decorate_method).to eq :decorate
45
+ end
46
+
47
+ it "should be :new if decorator does not support :decorate_collection or :decorate" do
48
+ expect(subject.decorate_method).to eq :new
49
+ end
50
+
51
+ it "should be :decorate if decorator supports it and collection: false" do
52
+ allow(decorator).to receive(:decorate)
53
+ allow(decorator).to receive(:decorate_collection)
54
+ subject = klass.new(:conferences, decorator: decorator, collection: false)
55
+ expect(subject.decorate_method).to eq :decorate
56
+ end
57
+ end
58
+
59
+ describe "when name is singular" do
60
+ subject { klass.new(:conference, decorator: decorator) }
61
+ let(:decorator) { double }
62
+
63
+ it "should not be :decorate_collection even if decorator supports it" do
64
+ allow(decorator).to receive(:decorate_collection)
65
+ expect(subject.decorate_method).not_to eq :decorate_collection
66
+ end
67
+
68
+ it "should be :decorate_collection if decorator supports it and collection: true" do
69
+ allow(decorator).to receive(:decorate)
70
+ allow(decorator).to receive(:decorate_collection)
71
+ subject = klass.new(:conference, decorator: decorator, collection: true)
72
+ expect(subject.decorate_method).to eq :decorate_collection
73
+ end
74
+
75
+ it "should be :decorate if decorator supports it" do
76
+ allow(decorator).to receive(:decorate)
77
+ expect(subject.decorate_method).to eq :decorate
78
+ end
79
+
80
+ it "should be :new if decorator does not support :decorate" do
81
+ expect(subject.decorate_method).to eq :new
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,21 @@
1
+ class ConferencesController < ActionController::Base
2
+ include Rails.application.routes.url_helpers
3
+
4
+ expose_decorated :conference
5
+ expose_decorated :other_conference, model: Conference, decorator: CoolConferenceDecorator
6
+
7
+ def show
8
+ render :plain => "foo"
9
+ end
10
+ end
11
+
12
+ class AttendeesController < ActionController::Base
13
+ include Rails.application.routes.url_helpers
14
+
15
+ expose_decorated :attendee
16
+ expose_decorated :attendees, ->{ [Attendee.new, Attendee.new] }
17
+
18
+ def show
19
+ render :plain => "foo"
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'delegate'
2
+ require 'draper'
3
+
4
+ class ConferenceDecorator < SimpleDelegator
5
+ def decorated_object
6
+ __getobj__
7
+ end
8
+ end
9
+
10
+ class CoolConferenceDecorator < ConferenceDecorator
11
+ end
12
+
13
+ class AttendeeDecorator < Draper::Decorator
14
+ def full_name
15
+ "#{first_name} #{last_name}"
16
+ end
17
+
18
+ def self.find(id)
19
+ Attendee.find(id)
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ require 'active_support/all'
2
+
3
+ require 'decent_exposure'
4
+ require 'decent_decoration'
5
+
6
+ require 'action_controller'
7
+ require 'action_dispatch'
8
+ require 'active_model'
9
+
10
+ module Rails
11
+ class App
12
+ def env_config; {} end
13
+
14
+ def routes
15
+ @routes ||= ActionDispatch::Routing::RouteSet.new.tap do |routes|
16
+ routes.draw do
17
+ resources :conferences, only: %i(show)
18
+ resources :attendees, only: %i(show)
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def self.application
25
+ @app ||= App.new
26
+ end
27
+ end
28
+
29
+ require 'fixtures/models'
30
+ require 'fixtures/decorators'
31
+ require 'fixtures/controllers'
@@ -0,0 +1,31 @@
1
+ module Model
2
+ extend ActiveModel::Naming
3
+
4
+ def initialize(attrs={})
5
+ self.attributes = attrs
6
+ end
7
+
8
+ def attributes=(attributes)
9
+ attributes.each { |k,v| send("#{k}=", v) }
10
+ end
11
+
12
+ def self.included(klass)
13
+ def klass.find(id)
14
+ new if id
15
+ end
16
+
17
+ def klass.scoped
18
+ self
19
+ end
20
+ end
21
+ end
22
+
23
+ class Conference
24
+ include Model
25
+ attr_accessor :name, :location
26
+ end
27
+
28
+ class Attendee
29
+ include Model
30
+ attr_accessor :first_name, :last_name
31
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/fake_rails_application'
3
+ require 'rspec/rails'
4
+
5
+ describe AttendeesController, type: :controller do
6
+ before do
7
+ get :show, params: { id: 'dave' }
8
+ end
9
+
10
+ it "should be a decorator" do
11
+ expect(controller.view_context.attendee).to be_instance_of(AttendeeDecorator)
12
+ end
13
+
14
+ it "should be a decorator in collection" do
15
+ controller.view_context.attendees.each do |attendee|
16
+ expect(attendee).to be_instance_of(AttendeeDecorator)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ require 'fixtures/fake_rails_application'
2
+ require 'rspec/rails'
3
+
4
+ describe ConferencesController, type: :controller do
5
+ before do
6
+ get :show, params: { id: 'RuPy' }
7
+ end
8
+
9
+ describe "inside a view" do
10
+ it "should be a decorator" do
11
+ expect(controller.view_context.conference).to be_instance_of(ConferenceDecorator)
12
+ end
13
+
14
+ it "should have decorated conference" do
15
+ expect(controller.view_context.conference.decorated_object).to be_instance_of(Conference)
16
+ end
17
+
18
+ it "should be specified decorator" do
19
+ expect(controller.view_context.other_conference).to be_instance_of(CoolConferenceDecorator)
20
+ end
21
+
22
+ it "should cache decorator" do
23
+ expect(controller.view_context.conference.object_id).to eq controller.view_context.conference.object_id
24
+ end
25
+
26
+ it "should cache decorated object" do
27
+ expect(controller.view_context.conference.decorated_object.object_id).to eq controller.view_context.conference.decorated_object.object_id
28
+ end
29
+ end
30
+
31
+ describe "inside a controller" do
32
+ it "should be undecorated object" do
33
+ expect(controller.conference).to be_instance_of(Conference)
34
+ end
35
+
36
+ it "should not be specified decorator" do
37
+ expect(controller.other_conference).to be_instance_of(Conference)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ require 'active_support/all'
2
+ require 'decent_decoration'
3
+ require 'coveralls'
4
+
5
+ Coveralls.wear!
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decent_decoration-ruby3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomasz Pewiński
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: decent_exposure
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '6.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '6.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '6.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '6.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '6.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '6.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: draper
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ description: Use decent_exposure with decorators (e.g. Draper)
84
+ email:
85
+ - pewniak747@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CHANGELOG.md
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - decent_decoration.gemspec
99
+ - lib/decent_decoration.rb
100
+ - lib/decent_decoration/decorate.rb
101
+ - lib/decent_decoration/version.rb
102
+ - spec/decoration_spec.rb
103
+ - spec/fixtures/controllers.rb
104
+ - spec/fixtures/decorators.rb
105
+ - spec/fixtures/fake_rails_application.rb
106
+ - spec/fixtures/models.rb
107
+ - spec/integration/draper_spec.rb
108
+ - spec/integration/rails_application_spec.rb
109
+ - spec/spec_helper.rb
110
+ homepage: https://github.com/netguru/decent_decoration
111
+ licenses: []
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '3.0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.4.10
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Use decent_exposure with decorators (e.g. Draper)
132
+ test_files:
133
+ - spec/decoration_spec.rb
134
+ - spec/fixtures/controllers.rb
135
+ - spec/fixtures/decorators.rb
136
+ - spec/fixtures/fake_rails_application.rb
137
+ - spec/fixtures/models.rb
138
+ - spec/integration/draper_spec.rb
139
+ - spec/integration/rails_application_spec.rb
140
+ - spec/spec_helper.rb