aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/lazy_load_hooks.rb
Commit message (Collapse)AuthorAgeFilesLines
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* A Class is a Module so we remove one conditionalRafael Mendonça França2018-07-041-1/+1
|
* Use class_eval or instance_eval when triggering lazy load hooks:Edouard CHIN2018-07-031-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | - When lazy load hooks were triggered we were using `Object.instance_eval` which evaluates the block in the context of the class being passed. Most of the time that class was a `Class`. If one wants to define a instance method on the class then it wasn't possible. ```ruby class A; end; A.instance_eval do def foo puts 'bar' end end A.new.foo #> NoMethodError: undefined method `foo` A.foo #> bar ``` - This PR checks what object is passed when triggering the hooks and either call `class_eval` or `instance_eval`. My rational and assumptions being that if an instance of a class is passed, then the blocks needs to evaluate in the context of that instance (i.e. defining a method should only define it on that instance). On the other hand, if a Class or Module is passed when triggering hooks, then defining a method should define it on the class itself - #32776 Pushed me to introduce this change
* Pass missing name attribute to execute_hookAlberto Almagro2017-08-161-3/+3
| | | | Fixes commit 10bf93ef92a70ae511036134290bf0e2de184b5c created to solve issue #30025
* Allow lazy load hooks to be executed only onceAlberto Almagro2017-08-141-8/+26
| | | | Provide run_once: true option to on_load in case you want a hook only to be executed once. This may be useful in cases where executing a hook several times may have undesired side effects
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-111-0/+1
|
* Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-091-0/+1
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-2/+2
|
* [ci skip] Use class name instead of path to fileAndrey Molchanov2016-09-281-2/+2
|
* Add documentation about `ActiveSupport.on_load`mrageh2016-08-131-0/+2
| | | | | | | [ci skip] This commit adds some docs that explain how `LazyLoadHooks.on_load` method works.
* Wrap module around lazy load hooksmrageh2016-07-121-18/+26
| | | | | | | | | | | | | Fix for issue https://github.com/rails/rails/issues/25784 Prior to this commit the lazy_load_hooks.rb file contained important lazy load hooks. Since [7c90d91](https://github.com/rails/rails/commit/7c90d91c3c43bdbba25d38589aed0e2940af3bc8) the [documentation](http://api.rubyonrails.org/files/activesupport/lib/active_support/lazy_load_hooks_rb.html) did not display the comments in this file as the docs for load hooks. This commit wraps the code within this file in a module so we can display the documentation for `ActiveSupport` load hooks. By extending `ActiveSupport` with this module, all the methods within it should still be accessible through `ActiveSupport`.
* rails -> Rails [ci skip]Prathamesh Sonpatki2013-05-091-1/+1
|
* update AS docs [ci skip]Francesco Rodriguez2012-09-171-8/+10
|
* Ensure load hooks can be called more than once with different contexts.José Valim2012-03-061-6/+6
|
* Clean up module docs [ci skip]Vijay Dev2012-03-071-19/+19
| | | | Removed some useless docstrings and no-doc'ed some.
* Whitespace and example identationJosep M. Bach2010-08-151-7/+7
|
* Deletes trailing whitespaces (over text files only find * -type f -exec sed ↵Santiago Pastorino2010-08-141-2/+2
| | | | 's/[ \t]*$//' -i {} \;)
* Adding documentation regarding lazy_load_hooksNeeraj Singh2010-07-291-1/+20
|
* Reorganized initializers a bit to enable better hooks for common cases ↵wycats2010-05-151-4/+14
| | | | | | | | | | | | | | | without the need for Railtie. Specifically, the following hooks were added: * before_configuration: this hook is run immediately after the Application class comes into existence, but before the user has added any configuration. This is the appropriate place to set configuration for your plugin * before_initialize: This is run after all of the user's configuration has completed, but before any initializers have begun (in other words, it runs right after config/environments/{development,production,test}.rb) * after_initialize: This is run after all of the initializers have run. It is an appropriate place for forking in a preforking setup Each of these hooks may be used via ActiveSupport.on_load(name) { }. In all these cases, the context inside the block will be the Application object. This means that for simple cases, you can use these hooks without needing to create a Railtie.
* Replace the placeholder base_hook API with on_load. To specify some code thatwycats2010-03-291-19/+11
| | | | | | | | should run during framework load do: ActiveSupport.on_load(:action_controller) do # Code run in the context of AC::Base end
* Make many parts of Rails lazy. In order to facilitate this,wycats2010-03-071-0/+25
add lazy_load_hooks.rb, which allows us to declare code that should be run at some later time. For instance, this allows us to defer requiring ActiveRecord::Base at boot time purely to apply configuration. Instead, we register a hook that should apply configuration once ActiveRecord::Base is loaded. With these changes, brings down total boot time of a new app to 300ms in production and 400ms in dev. TODO: rename base_hook