ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:99950] [Ruby master Feature#17156] Refinements per directory tree
@ 2020-09-06  1:59 daniel
  2020-10-22  3:14 ` [ruby-core:100490] " daniel
  2020-12-07  5:19 ` [ruby-core:101277] " marcandre-ruby-core
  0 siblings, 2 replies; 3+ messages in thread
From: daniel @ 2020-09-06  1:59 UTC (permalink / raw)
  To: ruby-core

Issue #17156 has been reported by Dan0042 (Daniel DeLorme).

----------------------------------------
Feature #17156: Refinements per directory tree
https://bugs.ruby-lang.org/issues/17156

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
----------------------------------------
One of the main use-case for refinements is to enable extensions to core classes for a given codebase (app or gem) without impacting the other codebases. Let's call it sandboxed monkey-patching. Note that you usually want this for an entire codebase, not specific files.

But refinements can only be enabled on a per-module or per-file basis. So if you want refinements in your entire project, you need to add the "using" boilerplate to every single file. I find this too bothersome. I have some core extensions that I would love to convert into refinements, but adding a "using" statement to every file is too much of a pain; I find it not worth the trouble, especially considering that the risk of conflicts due to monkey-patching is very low to start with.

So I would like the ability to enable refinements for all the files in a project, that is, on a whole directory tree.

I'd like to keep it simple. So my idea is to have something like `using M, subdirs: true` that would be equivalent to `using M` at the top of every file loaded _after that point_ within the directory tree of the file with the `using` statement. So the typical case would be, for gem "foobar" which is loaded via `require "foobar"`, you'd put the `using` statement at the top of the gem's main `foobar.rb` file, and then every file loaded within the gem's directory would benefit from those refinements. Similarly, if you want to use certain refinements throughout your app, put them in a file in the root dir of the app and load it early in the initialization process.

Note: With this design I wanted to avoid the possibility that someone could apply refinements globally by writing `using M, subdirs: "/"`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:100490] [Ruby master Feature#17156] Refinements per directory tree
  2020-09-06  1:59 [ruby-core:99950] [Ruby master Feature#17156] Refinements per directory tree daniel
@ 2020-10-22  3:14 ` daniel
  2020-12-07  5:19 ` [ruby-core:101277] " marcandre-ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: daniel @ 2020-10-22  3:14 UTC (permalink / raw)
  To: ruby-core

Issue #17156 has been updated by Dan0042 (Daniel DeLorme).


@shugo, may I ask for your opinion on this?

----------------------------------------
Feature #17156: Refinements per directory tree
https://bugs.ruby-lang.org/issues/17156#change-88109

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
----------------------------------------
One of the main use case for refinements is to enable extensions to core classes for a given codebase (app or gem) without impacting the other codebases. Let's call it sandboxed monkey-patching. Note that you usually want this for an entire codebase, not specific files.

But refinements can only be enabled on a per-module or per-file basis. So if you want refinements in your entire project, you need to add the "using" boilerplate to every single file. I find this too bothersome. I have some core extensions that I would love to convert into refinements, but adding a "using" statement to every file is too much of a pain; I find it not worth the trouble, especially considering that the risk of conflicts due to monkey-patching is very low to start with.

So I would like the ability to enable refinements for all the files in a project, that is, on a whole directory tree.

I'd like to keep it simple. So my idea is to have something like `using M, subdirs: true` that would be equivalent to `using M` at the top of every file loaded _after that point_ within the directory tree of the file with the `using` statement. So the typical case would be, for gem "foobar" which is loaded via `require "foobar"`, you'd put the `using` statement at the top of the gem's main `foobar.rb` file, and then every file loaded within the gem's directory would benefit from those refinements. Similarly, if you want to use certain refinements throughout your app, put them in a file in the root dir of the app and load it early in the initialization process.

By restricting this feature to the directory of the current file, we limit the possibility that someone can apply refinements globally by writing `using M, subdirs: "/"`

Also this would allow refinements to apply within erb templates, or any other code loaded via `eval(code, nil, filename, lineno)` where `filename` is within the targeted directory tree.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:101277] [Ruby master Feature#17156] Refinements per directory tree
  2020-09-06  1:59 [ruby-core:99950] [Ruby master Feature#17156] Refinements per directory tree daniel
  2020-10-22  3:14 ` [ruby-core:100490] " daniel
@ 2020-12-07  5:19 ` marcandre-ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: marcandre-ruby-core @ 2020-12-07  5:19 UTC (permalink / raw)
  To: ruby-core

Issue #17156 has been updated by marcandre (Marc-Andre Lafortune).


I believe a good solution would be a configurable RuboCop cop that could add it for you. It should be easily more customizable than any solution in core, while maintaining Matz' idea to avoid too much magic "hey where did this method come from".

If this interests you, please check https://github.com/rubocop-hq/rubocop/issues/9180

----------------------------------------
Feature #17156: Refinements per directory tree
https://bugs.ruby-lang.org/issues/17156#change-88956

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
----------------------------------------
One of the main use case for refinements is to enable extensions to core classes for a given codebase (app or gem) without impacting the other codebases. Let's call it sandboxed monkey-patching. Note that you usually want this for an entire codebase, not specific files.

But refinements can only be enabled on a per-module or per-file basis. So if you want refinements in your entire project, you need to add the "using" boilerplate to every single file. I find this too bothersome. I have some core extensions that I would love to convert into refinements, but adding a "using" statement to every file is too much of a pain; I find it not worth the trouble, especially considering that the risk of conflicts due to monkey-patching is very low to start with.

So I would like the ability to enable refinements for all the files in a project, that is, on a whole directory tree.

I'd like to keep it simple. So my idea is to have something like `using M, subdirs: true` that would be equivalent to `using M` at the top of every file loaded _after that point_ within the directory tree of the file with the `using` statement. So the typical case would be, for gem "foobar" which is loaded via `require "foobar"`, you'd put the `using` statement at the top of the gem's main `foobar.rb` file, and then every file loaded within the gem's directory would benefit from those refinements. Similarly, if you want to use certain refinements throughout your app, put them in a file in the root dir of the app and load it early in the initialization process.

By restricting this feature to the directory of the current file, we limit the possibility that someone can apply refinements globally by writing `using M, subdirs: "/"`

Also this would allow refinements to apply within erb templates, or any other code loaded via `eval(code, nil, filename, lineno)` where `filename` is within the targeted directory tree.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-07  5:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-06  1:59 [ruby-core:99950] [Ruby master Feature#17156] Refinements per directory tree daniel
2020-10-22  3:14 ` [ruby-core:100490] " daniel
2020-12-07  5:19 ` [ruby-core:101277] " marcandre-ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).