draper 2.1.0 → 3.0.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 +4 -4
- data/.codeclimate.yml +16 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +24 -0
- data/.gitignore +3 -1
- data/.rubocop.yml +11 -0
- data/.travis.yml +3 -7
- data/CHANGELOG.md +26 -0
- data/Gemfile +4 -5
- data/Guardfile +5 -5
- data/README.md +61 -11
- data/Rakefile +1 -1
- data/draper.gemspec +12 -10
- data/lib/draper.rb +8 -3
- data/lib/draper/automatic_delegation.rb +5 -3
- data/lib/draper/collection_decorator.rb +1 -11
- data/lib/draper/compatibility/api_only.rb +23 -0
- data/lib/draper/configuration.rb +15 -0
- data/lib/draper/decoratable.rb +3 -4
- data/lib/draper/decorator.rb +4 -24
- data/lib/draper/finders.rb +0 -0
- data/lib/draper/helper_proxy.rb +1 -8
- data/lib/draper/railtie.rb +12 -21
- data/lib/draper/tasks/test.rake +2 -15
- data/lib/draper/test/devise_helper.rb +1 -8
- data/lib/draper/test/minitest_integration.rb +0 -0
- data/lib/draper/test/rspec_integration.rb +1 -5
- data/lib/draper/test_case.rb +4 -8
- data/lib/draper/undecorate.rb +8 -0
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context.rb +3 -19
- data/lib/draper/view_context/build_strategy.rb +11 -2
- data/lib/generators/controller_override.rb +2 -2
- data/lib/generators/draper/install_generator.rb +14 -0
- data/lib/generators/draper/templates/application_decorator.rb +8 -0
- data/lib/generators/mini_test/decorator_generator.rb +1 -1
- data/lib/generators/rails/decorator_generator.rb +1 -8
- data/lib/generators/rspec/templates/decorator_spec.rb +2 -2
- data/spec/draper/collection_decorator_spec.rb +11 -26
- data/spec/draper/configuration_spec.rb +25 -0
- data/spec/draper/decoratable_spec.rb +29 -16
- data/spec/draper/decorated_association_spec.rb +9 -9
- data/spec/draper/decorates_assigned_spec.rb +6 -6
- data/spec/draper/decorator_spec.rb +112 -89
- data/spec/draper/draper_spec.rb +24 -0
- data/spec/draper/factory_spec.rb +26 -26
- data/spec/draper/finders_spec.rb +21 -21
- data/spec/draper/helper_proxy_spec.rb +3 -3
- data/spec/draper/lazy_helpers_spec.rb +2 -2
- data/spec/draper/undecorate_chain_spec.rb +20 -0
- data/spec/draper/view_context/build_strategy_spec.rb +26 -10
- data/spec/draper/view_context_spec.rb +49 -21
- data/spec/dummy/app/controllers/base_controller.rb +4 -0
- data/spec/dummy/app/controllers/posts_controller.rb +2 -2
- data/spec/dummy/app/decorators/post_decorator.rb +0 -0
- data/spec/dummy/app/views/posts/_post.html.erb +8 -6
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/initializers/draper.rb +3 -0
- data/spec/dummy/config/mongoid.yml +104 -41
- data/spec/dummy/db/schema.rb +4 -4
- data/spec/dummy/fast_spec/post_decorator_spec.rb +1 -1
- data/spec/dummy/lib/tasks/test.rake +1 -1
- data/spec/dummy/spec/decorators/active_model_serializers_spec.rb +4 -8
- data/spec/dummy/spec/decorators/devise_spec.rb +0 -9
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +2 -4
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +0 -8
- data/spec/dummy/spec/shared_examples/decoratable.rb +0 -2
- data/spec/dummy/test/decorators/minitest/devise_test.rb +0 -9
- data/spec/dummy/test/decorators/minitest/view_context_test.rb +3 -3
- data/spec/dummy/test/decorators/test_unit/devise_test.rb +0 -9
- data/spec/dummy/test/decorators/test_unit/view_context_test.rb +1 -1
- data/spec/generators/controller/controller_generator_spec.rb +3 -3
- data/spec/generators/decorator/decorator_generator_spec.rb +14 -12
- data/spec/generators/install/install_generator_spec.rb +19 -0
- data/spec/integration/integration_spec.rb +11 -8
- data/spec/performance/benchmark.rb +1 -1
- data/spec/spec_helper.rb +4 -4
- data/spec/support/matchers/have_text.rb +2 -2
- data/spec/support/shared_examples/view_helpers.rb +8 -8
- metadata +71 -29
- data/gemfiles/4.0.gemfile +0 -3
- data/gemfiles/4.1.gemfile +0 -3
- data/gemfiles/4.2.gemfile +0 -3
- data/spec/dummy/app/controllers/application_controller.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f2c896cc71e7e4e654a5d65907dd0ec4cefed7f
|
4
|
+
data.tar.gz: ce50051cf161e9416483a40797d38ae2d2da3384
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 527adb1c71ce28f23bb9be4186fe857c543a26edd8d20404f1e2a6db51e819143dd9c7973f7735746457c2a8a392e7a6d5b8a79232d26a1694035e09441a98f4
|
7
|
+
data.tar.gz: 0ed34d19d3b0300ea733392aab2c4cceaa1b284efc71e84452331fea4c9c11c68c7dc00baa7802a864d60f69bfb42beb8f5cecf959ed5ebf01b8a24c7e676f3f
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
## Description
|
2
|
+
Detail your changes here.
|
3
|
+
A few sentences describing the overall goals of the pull request's commits will suffice.
|
4
|
+
Some questions you might answer:
|
5
|
+
|
6
|
+
* Why was this change required?
|
7
|
+
* Did you have any tough decisions to make? Which one(s) did you go with and why?
|
8
|
+
* Are there any deployment impacts to this change?
|
9
|
+
* Is there something you aren't happy with or that needs extra attention?
|
10
|
+
|
11
|
+
## Testing
|
12
|
+
Outline steps to test your changes.
|
13
|
+
|
14
|
+
1. Go here.
|
15
|
+
1. Click this.
|
16
|
+
1. See that.
|
17
|
+
|
18
|
+
## To-Dos
|
19
|
+
- [ ] tests
|
20
|
+
- [ ] documentation
|
21
|
+
|
22
|
+
## References
|
23
|
+
* [GitHub Issue ####](https://github.com/drapergem/draper/issues/####)
|
24
|
+
* [GitHub Pull Request ####](https://github.com/drapergem/draper/pull/####)
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# Draper Changelog
|
2
2
|
|
3
|
+
## 3.0.0 - 2017
|
4
|
+
|
5
|
+
### Breaking Changes
|
6
|
+
* Rename UninferrableSourceError to UninferrableObjectError [#768](https://github.com/drapergem/draper/pull/768)
|
7
|
+
* Remove conflicting source aliases: `source`, `to_source`, `source_class` and `source_class?` [#786](https://github.com/drapergem/draper/pull/786)
|
8
|
+
|
9
|
+
### New Features
|
10
|
+
* Generator for creating `ApplicationDecorator` that other decorators inherit from [#796](https://github.com/drapergem/draper/pull/796)
|
11
|
+
* Draper configuration with ability to customize the controller Draper uses [#788](https://github.com/drapergem/draper/pull/788)
|
12
|
+
* Added support for Rails 5 API-only applications [#793](https://github.com/drapergem/draper/pull/793)
|
13
|
+
* Added support for Rails runner [#739](https://github.com/drapergem/draper/pull/739)
|
14
|
+
|
15
|
+
### Other Changes
|
16
|
+
* Clear view context when the controller changes [#799](https://github.com/drapergem/draper/pull/799)
|
17
|
+
* Removed previously deprecated functionality [#785](https://github.com/drapergem/draper/pull/785)
|
18
|
+
* Only delegate === if other is an instance of a class that inherits from `Decorator` [#720](https://github.com/drapergem/draper/pull/720)
|
19
|
+
* Always default to `CollectionDecorator` when `NameError` is raised [#795](https://github.com/drapergem/draper/pull/795)
|
20
|
+
* Fixed issues in order to support Rails 5.1
|
21
|
+
* Fixed a bug where helpers were used inside a decorator and this decorator was used outside of controller context
|
22
|
+
|
23
|
+
## 3.0.0.pre1 - 2016-07-10
|
24
|
+
|
25
|
+
* Added support for Rails 5, dropped 4.0 - 4.2
|
26
|
+
* Ruby >= 2.2 is required, matching Rails 5
|
27
|
+
* Dropped support for ActiveModelSerializers 0.8
|
28
|
+
|
3
29
|
## 2.1.0 - 2015-03-26
|
4
30
|
|
5
31
|
* Cleared most issues and merged a few PRs
|
data/Gemfile
CHANGED
@@ -7,10 +7,9 @@ platforms :ruby do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
platforms :jruby do
|
10
|
-
gem "minitest"
|
11
|
-
gem "activerecord-jdbcsqlite3-adapter"
|
10
|
+
gem "minitest"
|
11
|
+
gem "activerecord-jdbcsqlite3-adapter"
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
eval_gemfile File.expand_path("../gemfiles/#{version}.gemfile", __FILE__)
|
14
|
+
gem "rails", "~> 5.0"
|
15
|
+
gem "mongoid", github: "mongodb/mongoid"
|
data/Guardfile
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
def rspec_guard(options = {}, &block)
|
2
2
|
options = {
|
3
|
-
:
|
4
|
-
:
|
3
|
+
version: 2,
|
4
|
+
notification: false
|
5
5
|
}.merge(options)
|
6
6
|
|
7
7
|
guard 'rspec', options, &block
|
8
8
|
end
|
9
9
|
|
10
|
-
rspec_guard :
|
10
|
+
rspec_guard spec_paths: %w{spec/draper spec/generators} do
|
11
11
|
watch(%r{^spec/.+_spec\.rb$})
|
12
12
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
13
13
|
watch('spec/spec_helper.rb') { "spec" }
|
14
14
|
end
|
15
15
|
|
16
|
-
rspec_guard :
|
16
|
+
rspec_guard spec_paths: 'spec/integration', env: {'RAILS_ENV' => 'development'} do
|
17
17
|
watch(%r{^spec/.+_spec\.rb$})
|
18
18
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
19
19
|
watch('spec/spec_helper.rb') { "spec" }
|
20
20
|
end
|
21
21
|
|
22
|
-
rspec_guard :
|
22
|
+
rspec_guard spec_paths: 'spec/integration', env: {'RAILS_ENV' => 'production'} do
|
23
23
|
watch(%r{^spec/.+_spec\.rb$})
|
24
24
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
25
25
|
watch('spec/spec_helper.rb') { "spec" }
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Draper: View Models for Rails
|
2
2
|
|
3
3
|
[](http://travis-ci.org/drapergem/draper)
|
4
|
-
[](https://codeclimate.com/github/drapergem/draper)
|
5
|
+
[](http://inch-ci.org/github/drapergem/draper)
|
6
6
|
|
7
7
|
Draper adds an object-oriented layer of presentation logic to your Rails
|
8
8
|
application.
|
@@ -48,7 +48,7 @@ end
|
|
48
48
|
But it makes you a little uncomfortable. `publication_status` lives in a
|
49
49
|
nebulous namespace spread across all controllers and view. Down the road, you
|
50
50
|
might want to display the publication status of a `Book`. And, of course, your
|
51
|
-
design calls for a
|
51
|
+
design calls for a slightly different formatting to the date for a `Book`.
|
52
52
|
|
53
53
|
Now your helper method can either switch based on the input class type (poor
|
54
54
|
Ruby style), or you break it out into two methods, `book_publication_status` and
|
@@ -107,13 +107,13 @@ Decorators are the ideal place to:
|
|
107
107
|
|
108
108
|
## Installation
|
109
109
|
|
110
|
-
Add Draper to your Gemfile
|
110
|
+
As of version 3.0.0, Draper is only compatible with Rails 5 / Ruby 2.2 and later. Add Draper to your Gemfile.
|
111
111
|
|
112
112
|
```ruby
|
113
|
-
gem 'draper'
|
113
|
+
gem 'draper'
|
114
114
|
```
|
115
115
|
|
116
|
-
|
116
|
+
After that, run `bundle install` within your app's directory.
|
117
117
|
|
118
118
|
If you're upgrading from a 0.x release, the major changes are outlined [in the
|
119
119
|
wiki](https://github.com/drapergem/draper/wiki/Upgrading-to-1.0).
|
@@ -132,6 +132,12 @@ end
|
|
132
132
|
|
133
133
|
### Generators
|
134
134
|
|
135
|
+
To create an `ApplicationDecorator` that all generated decorators inherit from, run...
|
136
|
+
|
137
|
+
```
|
138
|
+
rails generate draper:install
|
139
|
+
```
|
140
|
+
|
135
141
|
When you have Draper installed and generate a controller...
|
136
142
|
|
137
143
|
```
|
@@ -276,6 +282,19 @@ omitted.
|
|
276
282
|
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
|
277
283
|
```
|
278
284
|
|
285
|
+
If needed, you can then set the collection_decorator_class of your CustomDecorator as follows:
|
286
|
+
```ruby
|
287
|
+
class ArticleDecorator < Draper::Decorator
|
288
|
+
def self.collection_decorator_class
|
289
|
+
PaginatingDecorator
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
ArticleDecorator.decorate_collection(@articles.paginate)
|
294
|
+
# => Collection decorated by PaginatingDecorator
|
295
|
+
# => Members decorated by ArticleDecorator
|
296
|
+
```
|
297
|
+
|
279
298
|
### Decorating Associated Objects
|
280
299
|
|
281
300
|
You can automatically decorate associated models when the primary model is
|
@@ -348,6 +367,18 @@ you'll have access to an ArticleDecorator object instead. In your controller you
|
|
348
367
|
can continue to use the `@article` instance variable to manipulate the model -
|
349
368
|
for example, `@article.comments.build` to add a new blank comment for a form.
|
350
369
|
|
370
|
+
## Configuration
|
371
|
+
Draper works out the box well, but also provides a hook for you to configure its
|
372
|
+
default functionality. For example, Draper assumes you have a base `ApplicationController`.
|
373
|
+
If your base controller is named something different (e.g. `BaseController`),
|
374
|
+
you can tell Draper to use it by adding the following to an initializer:
|
375
|
+
|
376
|
+
```ruby
|
377
|
+
Draper.configure do |config|
|
378
|
+
config.default_controller = BaseController
|
379
|
+
end
|
380
|
+
```
|
381
|
+
|
351
382
|
## Testing
|
352
383
|
|
353
384
|
Draper supports RSpec, MiniTest::Rails, and Test::Unit, and will add the
|
@@ -379,6 +410,15 @@ In your `Spork.prefork` block of `spec_helper.rb`, add this:
|
|
379
410
|
require 'draper/test/rspec_integration'
|
380
411
|
```
|
381
412
|
|
413
|
+
#### Custom Draper Controller ViewContext
|
414
|
+
If running tests in an engine setting with a controller other than "ApplicationController," set a custom controller in `spec_helper.rb`
|
415
|
+
|
416
|
+
```ruby
|
417
|
+
config.before(:each, type: :decorator) do |example|
|
418
|
+
Draper::ViewContext.controller = ExampleEngine::CustomRootController.new
|
419
|
+
end
|
420
|
+
```
|
421
|
+
|
382
422
|
### Isolated Tests
|
383
423
|
|
384
424
|
In tests, Draper needs to build a view context to access helper methods. By
|
@@ -455,7 +495,10 @@ end
|
|
455
495
|
|
456
496
|
When your decorator calls `delegate_all`, any method called on the decorator not
|
457
497
|
defined in the decorator itself will be delegated to the decorated object. This
|
458
|
-
|
498
|
+
includes calling `super` from within the decorator. A call to `super` from within
|
499
|
+
the decorator will first try to call the method on the parent decorator class. If
|
500
|
+
the method does not exist on the parent decorator class, it will then try to call
|
501
|
+
the method on the decorated `object`. This is a very permissive interface.
|
459
502
|
|
460
503
|
If you want to strictly control which methods are called within views, you can
|
461
504
|
choose to only delegate certain methods from the decorator to the source model:
|
@@ -564,13 +607,15 @@ end
|
|
564
607
|
|
565
608
|
This is only necessary when proxying class methods.
|
566
609
|
|
610
|
+
Once this association between the decorator and the model is set up, you can call
|
611
|
+
`SomeModel.decorator_class` to access class methods defined in the decorator.
|
612
|
+
If necessary, you can check if your model is decorated with `SomeModel.decorator_class?`.
|
613
|
+
|
567
614
|
### Making Models Decoratable
|
568
615
|
|
569
616
|
Models get their `decorate` method from the `Draper::Decoratable` module, which
|
570
617
|
is included in `ActiveRecord::Base` and `Mongoid::Document` by default. If
|
571
|
-
you're
|
572
|
-
ORM](https://github.com/drapergem/draper/wiki/Using-other-ORMs) (including
|
573
|
-
versions of Mongoid prior to 3.0), or want to decorate plain old Ruby objects,
|
618
|
+
you're using another ORM, or want to decorate plain old Ruby objects,
|
574
619
|
you can include this module manually.
|
575
620
|
|
576
621
|
## Contributors
|
@@ -579,9 +624,14 @@ Draper was conceived by Jeff Casimir and heavily refined by Steve Klabnik and a
|
|
579
624
|
great community of open source
|
580
625
|
[contributors](https://github.com/drapergem/draper/contributors).
|
581
626
|
|
582
|
-
###
|
627
|
+
### Current maintainers
|
628
|
+
|
629
|
+
* Cliff Braton (cliff.braton@gmail.com)
|
630
|
+
|
631
|
+
### Historical maintainers
|
583
632
|
|
584
633
|
* Jeff Casimir (jeff@jumpstartlab.com)
|
585
634
|
* Steve Klabnik (steve@jumpstartlab.com)
|
586
635
|
* Vasiliy Ermolovich
|
587
636
|
* Andrew Haines
|
637
|
+
* Sean Linsley
|
data/Rakefile
CHANGED
@@ -64,6 +64,6 @@ namespace "db" do
|
|
64
64
|
run_in_dummy_app "rm -f db/*.sqlite3"
|
65
65
|
run_in_dummy_app "RAILS_ENV=development rake db:schema:load db:seed"
|
66
66
|
run_in_dummy_app "RAILS_ENV=production rake db:schema:load db:seed"
|
67
|
-
run_in_dummy_app "RAILS_ENV=test rake db:schema:load"
|
67
|
+
run_in_dummy_app "RAILS_ENV=test rake db:environment:set db:schema:load"
|
68
68
|
end
|
69
69
|
end
|
data/draper.gemspec
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "draper/version"
|
1
|
+
require File.join(__dir__, "lib", "draper", "version")
|
4
2
|
|
5
3
|
Gem::Specification.new do |s|
|
6
4
|
s.name = "draper"
|
@@ -17,15 +15,19 @@ Gem::Specification.new do |s|
|
|
17
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
16
|
s.require_paths = ["lib"]
|
19
17
|
|
20
|
-
s.
|
21
|
-
|
18
|
+
s.required_ruby_version = '>= 2.2.2'
|
19
|
+
|
20
|
+
s.add_dependency 'activesupport', '~> 5.0'
|
21
|
+
s.add_dependency 'actionpack', '~> 5.0'
|
22
22
|
s.add_dependency 'request_store', '~> 1.0'
|
23
|
-
s.add_dependency 'activemodel', '
|
23
|
+
s.add_dependency 'activemodel', '~> 5.0'
|
24
|
+
s.add_dependency 'activemodel-serializers-xml', '~> 1.0'
|
24
25
|
|
25
26
|
s.add_development_dependency 'ammeter'
|
26
|
-
s.add_development_dependency 'rake'
|
27
|
-
s.add_development_dependency 'rspec-rails'
|
28
|
-
s.add_development_dependency 'minitest-rails'
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
s.add_development_dependency 'rspec-rails'
|
29
|
+
s.add_development_dependency 'minitest-rails'
|
29
30
|
s.add_development_dependency 'capybara'
|
30
|
-
s.add_development_dependency 'active_model_serializers'
|
31
|
+
s.add_development_dependency 'active_model_serializers', '~> 0.10'
|
32
|
+
s.add_development_dependency 'rubocop'
|
31
33
|
end
|
data/lib/draper.rb
CHANGED
@@ -9,7 +9,9 @@ require 'active_support/core_ext/hash/reverse_merge'
|
|
9
9
|
require 'active_support/core_ext/name_error'
|
10
10
|
|
11
11
|
require 'draper/version'
|
12
|
+
require 'draper/configuration'
|
12
13
|
require 'draper/view_helpers'
|
14
|
+
require 'draper/compatibility/api_only'
|
13
15
|
require 'draper/delegation'
|
14
16
|
require 'draper/automatic_delegation'
|
15
17
|
require 'draper/finders'
|
@@ -27,13 +29,16 @@ require 'draper/decorates_assigned'
|
|
27
29
|
require 'draper/railtie' if defined?(Rails)
|
28
30
|
|
29
31
|
module Draper
|
32
|
+
extend Draper::Configuration
|
33
|
+
|
30
34
|
def self.setup_action_controller(base)
|
31
35
|
base.class_eval do
|
36
|
+
include Draper::Compatibility::ApiOnly if base == ActionController::API
|
32
37
|
include Draper::ViewContext
|
33
38
|
extend Draper::HelperSupport
|
34
39
|
extend Draper::DecoratesAssigned
|
35
40
|
|
36
|
-
|
41
|
+
before_action :activate_draper
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
@@ -55,9 +60,9 @@ module Draper
|
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
58
|
-
class
|
63
|
+
class UninferrableObjectError < NameError
|
59
64
|
def initialize(klass)
|
60
|
-
super("Could not infer
|
65
|
+
super("Could not infer an object for #{klass}.")
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
@@ -2,12 +2,14 @@ module Draper
|
|
2
2
|
module AutomaticDelegation
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
# Delegates missing instance methods to the source object.
|
5
|
+
# Delegates missing instance methods to the source object. Note: This will delegate `super`
|
6
|
+
# method calls to `object` as well. Calling `super` will first try to call the method on
|
7
|
+
# the parent decorator class. If no method exists on the parent class, it will then try
|
8
|
+
# to call the method on the `object`.
|
6
9
|
def method_missing(method, *args, &block)
|
7
10
|
return super unless delegatable?(method)
|
8
11
|
|
9
|
-
|
10
|
-
send(method, *args, &block)
|
12
|
+
object.send(method, *args, &block)
|
11
13
|
end
|
12
14
|
|
13
15
|
# Checks if the decorator responds to an instance method, or is able to
|
@@ -42,17 +42,7 @@ module Draper
|
|
42
42
|
@decorated_collection ||= object.map{|item| decorate_item(item)}
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
# (`Enumerable#find`) or to the decorator class if not
|
47
|
-
# (`ActiveRecord::FinderMethods#find`)
|
48
|
-
def find(*args, &block)
|
49
|
-
if block_given?
|
50
|
-
decorated_collection.find(*args, &block)
|
51
|
-
else
|
52
|
-
ActiveSupport::Deprecation.warn("Using ActiveRecord's `find` on a CollectionDecorator is deprecated. Call `find` on a model, and then decorate the result", caller)
|
53
|
-
decorate_item(object.find(*args))
|
54
|
-
end
|
55
|
-
end
|
45
|
+
delegate :find, to: :decorated_collection
|
56
46
|
|
57
47
|
def to_s
|
58
48
|
"#<#{self.class.name} of #{decorator_class || "inferred decorators"} for #{object.inspect}>"
|