draper 4.0.1 → 4.0.6
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 +4 -4
- data/.rspec +1 -2
- data/CHANGELOG.md +40 -0
- data/README.md +26 -7
- data/lib/draper/automatic_delegation.rb +16 -6
- data/lib/draper/compatibility/broadcastable.rb +24 -0
- data/lib/draper/compatibility/global_id.rb +9 -5
- data/lib/draper/decoratable/collection_proxy.rb +15 -0
- data/lib/draper/decoratable.rb +7 -2
- data/lib/draper/helper_proxy.rb +2 -1
- data/lib/draper/lazy_helpers.rb +1 -1
- data/lib/draper/query_methods.rb +2 -2
- data/lib/draper/railtie.rb +14 -5
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context/build_strategy.rb +1 -9
- data/lib/draper/view_helpers.rb +1 -1
- data/lib/draper.rb +2 -6
- metadata +29 -230
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -24
- data/.gitignore +0 -18
- data/.travis.yml +0 -28
- data/Gemfile +0 -23
- data/draper.gemspec +0 -34
- data/spec/draper/collection_decorator_spec.rb +0 -290
- data/spec/draper/configuration_spec.rb +0 -49
- data/spec/draper/decoratable/equality_spec.rb +0 -10
- data/spec/draper/decoratable_spec.rb +0 -235
- data/spec/draper/decorated_association_spec.rb +0 -82
- data/spec/draper/decorates_assigned_spec.rb +0 -71
- data/spec/draper/decorator_spec.rb +0 -872
- data/spec/draper/draper_spec.rb +0 -25
- data/spec/draper/factory_spec.rb +0 -247
- data/spec/draper/finders_spec.rb +0 -166
- data/spec/draper/helper_proxy_spec.rb +0 -61
- data/spec/draper/lazy_helpers_spec.rb +0 -21
- data/spec/draper/query_methods/load_strategy_spec.rb +0 -26
- data/spec/draper/query_methods_spec.rb +0 -70
- data/spec/draper/undecorate_chain_spec.rb +0 -20
- data/spec/draper/undecorate_spec.rb +0 -19
- data/spec/draper/view_context/build_strategy_spec.rb +0 -132
- data/spec/draper/view_context_spec.rb +0 -182
- data/spec/draper/view_helpers_spec.rb +0 -8
- data/spec/dummy/.rspec +0 -2
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/config/manifest.js +0 -3
- data/spec/dummy/app/controllers/application_controller.rb +0 -2
- data/spec/dummy/app/controllers/base_controller.rb +0 -4
- data/spec/dummy/app/controllers/localized_urls.rb +0 -5
- data/spec/dummy/app/controllers/posts_controller.rb +0 -20
- data/spec/dummy/app/decorators/mongoid_post_decorator.rb +0 -4
- data/spec/dummy/app/decorators/post_decorator.rb +0 -60
- data/spec/dummy/app/helpers/application_helper.rb +0 -5
- data/spec/dummy/app/jobs/publish_post_job.rb +0 -7
- data/spec/dummy/app/mailers/application_mailer.rb +0 -3
- data/spec/dummy/app/mailers/post_mailer.rb +0 -19
- data/spec/dummy/app/models/admin.rb +0 -5
- data/spec/dummy/app/models/application_record.rb +0 -3
- data/spec/dummy/app/models/mongoid_post.rb +0 -5
- data/spec/dummy/app/models/post.rb +0 -3
- data/spec/dummy/app/models/user.rb +0 -5
- data/spec/dummy/app/views/layouts/application.html.erb +0 -11
- data/spec/dummy/app/views/post_mailer/decorated_email.html.erb +0 -1
- data/spec/dummy/app/views/posts/_post.html.erb +0 -42
- data/spec/dummy/app/views/posts/show.html.erb +0 -1
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/config/application.rb +0 -68
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -33
- data/spec/dummy/config/environments/production.rb +0 -57
- data/spec/dummy/config/environments/test.rb +0 -33
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/draper.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -8
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/mongoid.yml +0 -142
- data/spec/dummy/config/routes.rb +0 -9
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/migrate/20121019115657_create_posts.rb +0 -8
- data/spec/dummy/db/schema.rb +0 -21
- data/spec/dummy/db/seeds.rb +0 -2
- data/spec/dummy/fast_spec/post_decorator_spec.rb +0 -37
- data/spec/dummy/lib/tasks/test.rake +0 -16
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/spec/decorators/active_model_serializers_spec.rb +0 -12
- data/spec/dummy/spec/decorators/devise_spec.rb +0 -55
- data/spec/dummy/spec/decorators/helpers_spec.rb +0 -21
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +0 -64
- data/spec/dummy/spec/decorators/spec_type_spec.rb +0 -7
- data/spec/dummy/spec/decorators/view_context_spec.rb +0 -22
- data/spec/dummy/spec/jobs/publish_post_job_spec.rb +0 -9
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +0 -25
- data/spec/dummy/spec/models/application_spec.rb +0 -7
- data/spec/dummy/spec/models/mongoid_post_spec.rb +0 -8
- data/spec/dummy/spec/models/post_spec.rb +0 -15
- data/spec/dummy/spec/shared_examples/decoratable.rb +0 -22
- data/spec/dummy/spec/spec_helper.rb +0 -8
- data/spec/dummy/test/decorators/minitest/devise_test.rb +0 -55
- data/spec/dummy/test/decorators/minitest/helpers_test.rb +0 -21
- data/spec/dummy/test/decorators/minitest/spec_type_test.rb +0 -52
- data/spec/dummy/test/decorators/minitest/view_context_test.rb +0 -24
- data/spec/dummy/test/decorators/test_unit/devise_test.rb +0 -55
- data/spec/dummy/test/decorators/test_unit/helpers_test.rb +0 -21
- data/spec/dummy/test/decorators/test_unit/view_context_test.rb +0 -24
- data/spec/dummy/test/minitest_helper.rb +0 -2
- data/spec/dummy/test/test_helper.rb +0 -3
- data/spec/generators/controller/controller_generator_spec.rb +0 -23
- data/spec/generators/decorator/decorator_generator_spec.rb +0 -93
- data/spec/generators/install/install_generator_spec.rb +0 -19
- data/spec/integration/integration_spec.rb +0 -70
- data/spec/performance/active_record.rb +0 -4
- data/spec/performance/benchmark.rb +0 -55
- data/spec/performance/decorators.rb +0 -45
- data/spec/performance/models.rb +0 -20
- data/spec/spec_helper.rb +0 -50
- data/spec/support/dummy_app.rb +0 -85
- data/spec/support/matchers/have_text.rb +0 -50
- data/spec/support/shared_examples/decoratable_equality.rb +0 -40
- data/spec/support/shared_examples/view_helpers.rb +0 -39
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c37ab7e42fe93c37a13899d6b51f1dbddfcb7a417eaad7531a3e11d59fb63442
|
|
4
|
+
data.tar.gz: 3ab092943fa340ef28abfe4974960201374f92e2defa6bd1c8fd90cd495b6056
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d700dbac01e145361e56c8b6fbf04c93b9156492e14659ba6724fa36be20ebdac6319c2bc2910beaf68b9cbe40271808ed17c23bed2c8a76361d438cc5b35033
|
|
7
|
+
data.tar.gz: bd8689b7de4f934d97dc48a564795ef91e2e859b586f7561c0ba3996e0f2b7434a29d8a9e497d5248b0e28074b854befdb86f6f20858f1816474755ec14fdca3
|
data/.rspec
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
--
|
|
2
|
-
--order rand
|
|
1
|
+
--format progress
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# Draper Changelog
|
|
2
2
|
|
|
3
|
+
## 4.0.6 - 2025-11-15
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
* Revert breaking change from v4.0.5
|
|
7
|
+
|
|
8
|
+
## 4.0.5 - 2025-11-12
|
|
9
|
+
|
|
10
|
+
### Fixes
|
|
11
|
+
* Remove unused files from package [#945](https://github.com/drapergem/draper/pull/945)
|
|
12
|
+
* Support Rails 8.1 [#949](https://github.com/drapergem/draper/pull/949)
|
|
13
|
+
|
|
14
|
+
## 4.0.4 - 2025-01-28
|
|
15
|
+
|
|
16
|
+
### Fixes
|
|
17
|
+
* Fix a `LoadError` caused by a cherry-pick issue in version 4.0.3
|
|
18
|
+
|
|
19
|
+
## 4.0.3 - 2025-01-27
|
|
20
|
+
|
|
21
|
+
Added support for latest Ruby (upto 3.4) and Rails (upto 8) versions.
|
|
22
|
+
|
|
23
|
+
### Fixes
|
|
24
|
+
* Fix `CollectionDecorator#respond_to?` for non-ORM collections [#920](https://github.com/drapergem/draper/pull/920)
|
|
25
|
+
* Fix issues with using Draper outside of controller scope [#927](https://github.com/drapergem/draper/pull/927)
|
|
26
|
+
* Fix decoration of AR associations [#932](https://github.com/drapergem/draper/pull/932)
|
|
27
|
+
|
|
28
|
+
### Other Changes
|
|
29
|
+
* Improve performance of delegation via `delegate_all` [#911](https://github.com/drapergem/draper/pull/911)
|
|
30
|
+
* Improve README [#878](https://github.com/drapergem/draper/pull/878), [#922](https://github.com/drapergem/draper/pull/922), [#934](https://github.com/drapergem/draper/pull/934)
|
|
31
|
+
|
|
32
|
+
## 4.0.2 - 2021-05-27
|
|
33
|
+
|
|
34
|
+
### Fixes
|
|
35
|
+
* Fix kwargs usage for Ruby 3 compatibility [#885](https://github.com/drapergem/draper/pull/885)
|
|
36
|
+
* Fix ruby warnings for "ambiguous first argument" [#881](https://github.com/drapergem/draper/pull/881)
|
|
37
|
+
* Fix rake warnings in CI [#897](https://github.com/drapergem/draper/pull/897)
|
|
38
|
+
* Fix decoration spec [#895](https://github.com/drapergem/draper/pull/895)
|
|
39
|
+
|
|
40
|
+
### Other Changes
|
|
41
|
+
* Migration from Travis CI to GitHub Actions [#893](https://github.com/drapergem/draper/pull/893), [#896](https://github.com/drapergem/draper/pull/896), [#903](https://github.com/drapergem/draper/pull/903)
|
|
42
|
+
|
|
3
43
|
## 4.0.1 - 2020-03-25
|
|
4
44
|
|
|
5
45
|
### Fixes
|
data/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# Draper: View Models for Rails
|
|
2
2
|
|
|
3
|
-
[](https://codeclimate.com/github/drapergem/draper)
|
|
5
|
-
[](https://codeclimate.com/github/drapergem/draper/test_coverage)
|
|
3
|
+
[](https://github.com/drapergem/draper/actions?query=workflow%3Aci+branch%3Amaster)
|
|
6
4
|
[](http://inch-ci.org/github/drapergem/draper)
|
|
7
5
|
|
|
8
6
|
Draper adds an object-oriented layer of presentation logic to your Rails
|
|
@@ -131,6 +129,17 @@ class ArticleDecorator < Draper::Decorator
|
|
|
131
129
|
end
|
|
132
130
|
```
|
|
133
131
|
|
|
132
|
+
|
|
133
|
+
To decorate a model in a namespace e.g. `Admin::Catalogue` place the decorator under the
|
|
134
|
+
directory `app/decorators/admin` in the same way you would with views and models.
|
|
135
|
+
|
|
136
|
+
```ruby
|
|
137
|
+
# app/decorators/admin/catalogue_decorator.rb
|
|
138
|
+
class Admin::CatalogueDecorator < Draper::Decorator
|
|
139
|
+
# ...
|
|
140
|
+
end
|
|
141
|
+
```
|
|
142
|
+
|
|
134
143
|
### Generators
|
|
135
144
|
|
|
136
145
|
To create an `ApplicationDecorator` that all generated decorators inherit from, run...
|
|
@@ -155,6 +164,15 @@ rails generate decorator Article
|
|
|
155
164
|
|
|
156
165
|
...to create the `ArticleDecorator`.
|
|
157
166
|
|
|
167
|
+
If you don't want Rails to generate decorator files when generating a new controller,
|
|
168
|
+
you can add the following configuration to your `config/application.rb` file:
|
|
169
|
+
|
|
170
|
+
```ruby
|
|
171
|
+
config.generators do |g|
|
|
172
|
+
g.decorator false
|
|
173
|
+
end
|
|
174
|
+
```
|
|
175
|
+
|
|
158
176
|
### Accessing Helpers
|
|
159
177
|
|
|
160
178
|
Normal Rails helpers are still useful for lots of tasks. Both Rails' provided
|
|
@@ -652,9 +670,8 @@ you can include this module manually.
|
|
|
652
670
|
[Active Job](http://edgeguides.rubyonrails.org/active_job_basics.html) allows you to pass ActiveRecord
|
|
653
671
|
objects to background tasks directly and performs the necessary serialization and deserialization. In
|
|
654
672
|
order to do this, arguments to a background job must implement [Global ID](https://github.com/rails/globalid).
|
|
655
|
-
|
|
656
|
-
you can pass decorated objects to background jobs,
|
|
657
|
-
deserialized.
|
|
673
|
+
Decorators implement Global ID.
|
|
674
|
+
This means you can pass decorated objects to background jobs, and get them just as decorated when deserialized.
|
|
658
675
|
|
|
659
676
|
## Contributors
|
|
660
677
|
|
|
@@ -664,7 +681,8 @@ great community of open source
|
|
|
664
681
|
|
|
665
682
|
### Current maintainers
|
|
666
683
|
|
|
667
|
-
*
|
|
684
|
+
* Alexander Senko (Alexander.Senko@gmail.com)
|
|
685
|
+
* Yuji Yaginuma (yuuji.yaginuma@gmail.com)
|
|
668
686
|
|
|
669
687
|
### Historical maintainers
|
|
670
688
|
|
|
@@ -673,3 +691,4 @@ great community of open source
|
|
|
673
691
|
* Vasiliy Ermolovich
|
|
674
692
|
* Andrew Haines
|
|
675
693
|
* Sean Linsley
|
|
694
|
+
* Cliff Braton (cliff.braton@gmail.com)
|
|
@@ -6,7 +6,7 @@ module Draper
|
|
|
6
6
|
# method calls to `object` as well. Calling `super` will first try to call the method on
|
|
7
7
|
# the parent decorator class. If no method exists on the parent class, it will then try
|
|
8
8
|
# to call the method on the `object`.
|
|
9
|
-
def method_missing(method, *args, &block)
|
|
9
|
+
ruby2_keywords def method_missing(method, *args, &block)
|
|
10
10
|
return super unless delegatable?(method)
|
|
11
11
|
|
|
12
12
|
object.send(method, *args, &block)
|
|
@@ -18,16 +18,26 @@ module Draper
|
|
|
18
18
|
super || delegatable?(method)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
#
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
# The inherit argument for `private_method_defined?` is supported since Ruby 2.6.
|
|
22
|
+
if RUBY_VERSION >= "2.6"
|
|
23
|
+
# @private
|
|
24
|
+
def delegatable?(method)
|
|
25
|
+
return if self.class.private_method_defined?(method, false)
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
object.respond_to?(method)
|
|
28
|
+
end
|
|
29
|
+
else
|
|
30
|
+
# @private
|
|
31
|
+
def delegatable?(method)
|
|
32
|
+
return if private_methods(false).include?(method)
|
|
33
|
+
|
|
34
|
+
object.respond_to?(method)
|
|
35
|
+
end
|
|
26
36
|
end
|
|
27
37
|
|
|
28
38
|
module ClassMethods
|
|
29
39
|
# Proxies missing class methods to the source class.
|
|
30
|
-
def method_missing(method, *args, &block)
|
|
40
|
+
ruby2_keywords def method_missing(method, *args, &block)
|
|
31
41
|
return super unless delegatable?(method)
|
|
32
42
|
|
|
33
43
|
object_class.send(method, *args, &block)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Draper
|
|
4
|
+
module Compatibility
|
|
5
|
+
# It would look consistent to use decorated objects inside templates broadcasted with
|
|
6
|
+
# Turbo::Broadcastable.
|
|
7
|
+
#
|
|
8
|
+
# This compatibility patch fixes the issue by overriding the original defaults to decorate the
|
|
9
|
+
# object, that's passed to the partial in a local variable.
|
|
10
|
+
module Broadcastable
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def broadcast_rendering_with_defaults(options)
|
|
14
|
+
return super unless decorator_class?
|
|
15
|
+
|
|
16
|
+
# Add the decorated current instance into the locals (see original method for details).
|
|
17
|
+
options[:locals] =
|
|
18
|
+
(options[:locals] || {}).reverse_merge!(model_name.element.to_sym => decorate)
|
|
19
|
+
|
|
20
|
+
super
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -5,17 +5,21 @@ module Draper
|
|
|
5
5
|
# and deserialization. In order to do this, arguments to a background job must implement
|
|
6
6
|
# [Global ID](https://github.com/rails/globalid).
|
|
7
7
|
#
|
|
8
|
-
# This compatibility patch implements Global ID for decorated objects by
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
8
|
+
# This compatibility patch implements Global ID for decorated objects by defining `.find(id)`
|
|
9
|
+
# class method that uses the original one and decorates the result.
|
|
10
|
+
# This means you can pass decorated objects to background jobs and they will be decorated when
|
|
11
|
+
# deserialized.
|
|
12
12
|
module GlobalID
|
|
13
13
|
extend ActiveSupport::Concern
|
|
14
14
|
|
|
15
15
|
included do
|
|
16
16
|
include ::GlobalID::Identification
|
|
17
|
+
end
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
class_methods do
|
|
20
|
+
def find(*args)
|
|
21
|
+
object_class.find(*args).decorate
|
|
22
|
+
end
|
|
19
23
|
end
|
|
20
24
|
end
|
|
21
25
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Draper
|
|
2
|
+
module Decoratable
|
|
3
|
+
module CollectionProxy
|
|
4
|
+
# Decorates a collection of objects. Used at the end of a scope chain.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# company.products.popular.decorate
|
|
8
|
+
# @param [Hash] options
|
|
9
|
+
# see {Decorator.decorate_collection}.
|
|
10
|
+
def decorate(options = {})
|
|
11
|
+
decorator_class.decorate_collection(load_target, options.reverse_merge(with: nil))
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/draper/decoratable.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'draper/decoratable/equality'
|
|
2
|
+
require 'draper/compatibility/broadcastable'
|
|
2
3
|
|
|
3
4
|
module Draper
|
|
4
5
|
# Provides shortcuts to decorate objects directly, so you can do
|
|
@@ -11,6 +12,12 @@ module Draper
|
|
|
11
12
|
extend ActiveSupport::Concern
|
|
12
13
|
include Draper::Decoratable::Equality
|
|
13
14
|
|
|
15
|
+
autoload :CollectionProxy, 'draper/decoratable/collection_proxy'
|
|
16
|
+
|
|
17
|
+
included do
|
|
18
|
+
prepend Draper::Compatibility::Broadcastable if defined? Turbo::Broadcastable
|
|
19
|
+
end
|
|
20
|
+
|
|
14
21
|
# Decorates the object using the inferred {#decorator_class}.
|
|
15
22
|
# @param [Hash] options
|
|
16
23
|
# see {Decorator#initialize}
|
|
@@ -87,8 +94,6 @@ module Draper
|
|
|
87
94
|
def ===(other)
|
|
88
95
|
super || (other.is_a?(Draper::Decorator) && super(other.object))
|
|
89
96
|
end
|
|
90
|
-
|
|
91
97
|
end
|
|
92
|
-
|
|
93
98
|
end
|
|
94
99
|
end
|
data/lib/draper/helper_proxy.rb
CHANGED
|
@@ -8,7 +8,7 @@ module Draper
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
# Sends helper methods to the view context.
|
|
11
|
-
def method_missing(method, *args, &block)
|
|
11
|
+
ruby2_keywords def method_missing(method, *args, &block)
|
|
12
12
|
self.class.define_proxy method
|
|
13
13
|
send(method, *args, &block)
|
|
14
14
|
end
|
|
@@ -31,6 +31,7 @@ module Draper
|
|
|
31
31
|
define_method name do |*args, &block|
|
|
32
32
|
view_context.send(name, *args, &block)
|
|
33
33
|
end
|
|
34
|
+
ruby2_keywords name
|
|
34
35
|
end
|
|
35
36
|
end
|
|
36
37
|
end
|
data/lib/draper/lazy_helpers.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Draper
|
|
|
4
4
|
# bazillion methods.
|
|
5
5
|
module LazyHelpers
|
|
6
6
|
# Sends missing methods to the {HelperProxy}.
|
|
7
|
-
def method_missing(method, *args, &block)
|
|
7
|
+
ruby2_keywords def method_missing(method, *args, &block)
|
|
8
8
|
helpers.send(method, *args, &block)
|
|
9
9
|
rescue NoMethodError
|
|
10
10
|
super
|
data/lib/draper/query_methods.rb
CHANGED
|
@@ -3,14 +3,14 @@ require_relative 'query_methods/load_strategy'
|
|
|
3
3
|
module Draper
|
|
4
4
|
module QueryMethods
|
|
5
5
|
# Proxies missing query methods to the source class if the strategy allows.
|
|
6
|
-
def method_missing(method, *args, &block)
|
|
6
|
+
ruby2_keywords def method_missing(method, *args, &block)
|
|
7
7
|
return super unless strategy.allowed? method
|
|
8
8
|
|
|
9
9
|
object.send(method, *args, &block).decorate(with: decorator_class, context: context)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def respond_to_missing?(method, include_private = false)
|
|
13
|
-
strategy.allowed?(method) || super
|
|
13
|
+
object.respond_to?(method) && strategy.allowed?(method) || super
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
private
|
data/lib/draper/railtie.rb
CHANGED
|
@@ -33,10 +33,14 @@ module Draper
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
initializer 'draper.setup_orm' do
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
ActiveSupport.on_load :active_record do
|
|
37
|
+
include Draper::Decoratable
|
|
38
|
+
|
|
39
|
+
ActiveRecord::Associations::CollectionProxy.include Draper::Decoratable::CollectionProxy
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
ActiveSupport.on_load :mongoid do
|
|
43
|
+
include Draper::Decoratable
|
|
40
44
|
end
|
|
41
45
|
end
|
|
42
46
|
|
|
@@ -52,7 +56,12 @@ module Draper
|
|
|
52
56
|
Draper::ViewContext.build
|
|
53
57
|
end
|
|
54
58
|
|
|
55
|
-
console
|
|
59
|
+
console do
|
|
60
|
+
initialize_view_context
|
|
61
|
+
if ActiveSupport.gem_version >= Gem::Version.new('8.1.0')
|
|
62
|
+
ActiveSupport::ExecutionContext.nestable = false
|
|
63
|
+
end
|
|
64
|
+
end
|
|
56
65
|
|
|
57
66
|
runner { initialize_view_context }
|
|
58
67
|
|
data/lib/draper/version.rb
CHANGED
|
@@ -38,17 +38,9 @@ module Draper
|
|
|
38
38
|
def controller
|
|
39
39
|
Draper::ViewContext.controller ||= Draper.default_controller.new
|
|
40
40
|
Draper::ViewContext.controller.tap do |controller|
|
|
41
|
-
controller.request ||=
|
|
41
|
+
controller.request ||= ActionDispatch::TestRequest.create
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
|
-
|
|
45
|
-
def new_test_request(controller)
|
|
46
|
-
is_above_rails_5_1 ? ActionController::TestRequest.create(controller) : ActionController::TestRequest.create
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def is_above_rails_5_1
|
|
50
|
-
ActionController::TestRequest.method(:create).parameters.first == [:req, :controller_class]
|
|
51
|
-
end
|
|
52
44
|
end
|
|
53
45
|
end
|
|
54
46
|
end
|
data/lib/draper/view_helpers.rb
CHANGED
data/lib/draper.rb
CHANGED
|
@@ -8,6 +8,8 @@ require 'active_support/core_ext/hash/keys'
|
|
|
8
8
|
require 'active_support/core_ext/hash/reverse_merge'
|
|
9
9
|
require 'active_support/core_ext/name_error'
|
|
10
10
|
|
|
11
|
+
require 'ruby2_keywords'
|
|
12
|
+
|
|
11
13
|
require 'draper/version'
|
|
12
14
|
require 'draper/configuration'
|
|
13
15
|
require 'draper/view_helpers'
|
|
@@ -49,12 +51,6 @@ module Draper
|
|
|
49
51
|
end
|
|
50
52
|
end
|
|
51
53
|
|
|
52
|
-
def self.setup_orm(base)
|
|
53
|
-
base.class_eval do
|
|
54
|
-
include Draper::Decoratable
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
54
|
class UninferrableDecoratorError < NameError
|
|
59
55
|
def initialize(klass)
|
|
60
56
|
super("Could not infer a decorator for #{klass}.")
|