Skip to content

Delegate properly to custom Resolver instances #1568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

bquorning
Copy link
Contributor

Let EmptyTemplateResolver creating instances of either EmptyTemplateResolver::ResolverDecorator or EmptyTemplateResolver::FileSystemResolver, depending on whether the given path is an ActionView::Resolver instance or not.

The new EmptyTemplateResolver::ResolverDecorator class simply delegates all method calls to its given resolver, except for #find_templates which it overrides to return templates that render with EmptyTemplateHandler.

Please note that the merge target is PR #1557, not master.

Introduce `EmptyTemplateResolverFactory` for creating instances of either
`EmptyTemplateResolverDecorator` or `EmptyTemplateFileSystemResolver`, depending
on whether the given path is an `ActionView::Resolver` instance or not.

The new `EmptyTemplateResolverDecorator` class simply delegates all method calls
to its given resolver, except for `#find_templates` which it overrides to return
templates that render with `EmptyTemplateHandler`.
@bquorning bquorning force-pushed the empty-template-resolver-builder branch from 52a2540 to f705bda Compare March 8, 2016 09:48
@bquorning
Copy link
Contributor Author

/cc @JonRowe @samphippen @pixeltrix

@fables-tales
Copy link
Member

LGTM, but I'd like another review.

#
# @private
class EmptyTemplateResolver < ::ActionView::FileSystemResolver
class EmptyTemplateResolverFactory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we build thinks like this we normally make them "instance less" to avoid unnecessary allocations, please refactor to a static instance, or better yet a module method. Can I also suggest a better name is desired? Something like DecoratePath or BuildEmptyTemplateResolver

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on both the allocation and naming concerns. How does EmptyTemplateResolver.build sound?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we could move EmptyTemplateFileSystemResolver and EmptyTemplateResolverDecorator into this EmptyTemplateResolver module (class), since they’re already supposed to be private and are only used by this factory class.

@bquorning
Copy link
Contributor Author

There, I pushed some changes:

  1. Changed the factory from an instance method to a class method: EmptyTemplateResolver.build
  2. Renamed and moved the ResolverDecorator and FileSystemResolver classes into EmptyTemplateResolver:: namespace.
  3. This allowed for extracting the duplicated mapping into an EmptyTemplateResolver.nullify_template_rendering method.

@fables-tales
Copy link
Member

@JonRowe LGTM

@fables-tales
Copy link
Member

Why are there no travis results for this branch?

@fables-tales fables-tales reopened this Mar 8, 2016
@fables-tales
Copy link
Member

(did not mean to close)

@bquorning
Copy link
Contributor Author

Why are there no travis results for this branch?

Perhaps because the merge target is not master branch?

@JonRowe
Copy link
Member

JonRowe commented Mar 8, 2016

Can you provide an example of the code this is intended to fix? I'm still hesitant around this as I haven't seen a real world scenario that's broken by the existing code...

@bquorning
Copy link
Contributor Author

@JonRowe I created a gist at https://gist.github.com/bquorning/6bf534e4b145b1738bb2. It’s a bit contrived, since I didn’t want to create tables and fetch custom templates from the database.

@ento
Copy link

ento commented Mar 9, 2016

re: example:
I have a group of namespaced controllers that share the same templates and a module of shared actions. I believe this PR will fix my anonymous controller test for the module, which uses a custom resolver to get to those templates.

@bquorning
Copy link
Contributor Author

By the way, should I rather make a PR against master, so that we can see some Travis runs?

@bquorning
Copy link
Contributor Author

Added 1 commit that allows Travis to run. Please don’t merge the PR with this commit included.

@bquorning
Copy link
Contributor Author

Build failed because of the new version of Rake that has Removed to support Ruby 1.8.x

@bquorning bquorning force-pushed the empty-template-resolver-builder branch 2 times, most recently from 194fea0 to 2b34a1b Compare March 9, 2016 12:23
@bquorning bquorning closed this Mar 9, 2016
@bquorning bquorning reopened this Mar 9, 2016
@bquorning
Copy link
Contributor Author

Superseded by #1580.

@bquorning bquorning closed this Mar 20, 2016
@bquorning bquorning deleted the empty-template-resolver-builder branch March 20, 2016 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants