From 939ac1144fa8335cb2233c9b434da784ec2c259f Mon Sep 17 00:00:00 2001 From: masatoshi_moritsuka Date: Sat, 9 Nov 2024 14:45:15 +0900 Subject: [PATCH] refactor(actionpack): move not changed methods to generated cf. https://github.com/ruby/gem_rbs_collection/pull/715#discussion_r1831042017 > Could you move the methods only what you changed, please? If my understanding is correct, only `ActionController::Helpers::ClassMethods#helper` and `AbstractController::Caching::Fragments::ClassMethods#fragment_cache_key` should be moved and modified. revert d7a4fb518abd0c258ea37b46d796bdcc31ba7e1a and 08b92b9e5ab942637942e3736972492ad9f5bff0 excluding 7d95c0de8ef6fcbc4f6bd6b6780a3daf6f8ec8b7 and 13676817064e47b30870a6687172b11192a349bd --- gems/actionpack/6.0/actioncontroller.rbs | 192 ----------------- gems/actionpack/6.0/actionpack-generated.rbs | 208 +++++++++++++++++++ 2 files changed, 208 insertions(+), 192 deletions(-) diff --git a/gems/actionpack/6.0/actioncontroller.rbs b/gems/actionpack/6.0/actioncontroller.rbs index 0e4628ed..b6243332 100644 --- a/gems/actionpack/6.0/actioncontroller.rbs +++ b/gems/actionpack/6.0/actioncontroller.rbs @@ -178,41 +178,7 @@ end module AbstractController module Helpers - extend ActiveSupport::Concern - - class MissingHelperError < LoadError - def initialize: (untyped error, untyped path) -> untyped - end - module ClassMethods - # When a class is inherited, wrap its helper module in a new module. - # This ensures that the parent class's module can be changed - # independently of the child class's. - def inherited: (untyped klass) -> untyped - - # Declare a controller method as a helper. For example, the following - # makes the +current_user+ and +logged_in?+ controller methods available - # to the view: - # class ApplicationController < ActionController::Base - # helper_method :current_user, :logged_in? - # - # def current_user - # @current_user ||= User.find_by(id: session[:user]) - # end - # - # def logged_in? - # current_user != nil - # end - # end - # - # In a view: - # <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%> - # - # ==== Parameters - # * method[, method] - A name or names of a method on the controller - # to be made available on the view. - def helper_method: (*untyped meths) -> untyped - # The +helper+ class method can take a series of helper module names, a block, or both. # # ==== Options @@ -248,63 +214,13 @@ module AbstractController # helper(:three, BlindHelper) { def mice() 'mice' end } # def helper: (*untyped args) ?{ () -> untyped } -> untyped - - # Clears up all existing helpers in this class, only keeping the helper - # with the same name as this class. - def clear_helpers: () -> untyped - - # Returns a list of modules, normalized from the acceptable kinds of - # helpers with the following behavior: - # - # String or Symbol:: :FooBar or "FooBar" becomes "foo_bar_helper", - # and "foo_bar_helper.rb" is loaded using require_dependency. - # - # Module:: No further processing - # - # After loading the appropriate files, the corresponding modules - # are returned. - # - # ==== Parameters - # * args - An array of helpers - # - # ==== Returns - # * Array - A normalized list of modules for the list of - # helpers provided. - def modules_for_helpers: (untyped args) -> untyped - - private - - # Makes all the (instance) methods in the helper module available to templates - # rendered through this controller. - # - # ==== Parameters - # * module - The module to include into the current helper module - # for the class - def add_template_helper: (untyped mod) -> untyped - - def default_helper_module!: () -> untyped end end end module AbstractController module Caching - # Fragment caching is used for caching various blocks within - # views without caching the entire action as a whole. This is - # useful when certain elements of an action change frequently or - # depend on complicated state while other parts rarely change or - # can be shared amongst multiple parties. The caching is done using - # the +cache+ helper available in the Action View. See - # ActionView::Helpers::CacheHelper for more information. - # - # While it's strongly recommended that you use key-based cache - # expiration (see links in CacheHelper for more information), - # it is also possible to manually expire caches. For example: - # - # expire_fragment('name_of_cache') module Fragments - extend ActiveSupport::Concern - module ClassMethods # Allows you to specify controller-wide key prefixes for # cache fragments. Pass either a constant +value+, or a block @@ -329,121 +245,13 @@ module AbstractController # end def fragment_cache_key: (?untyped? value) ?{ () -> untyped } -> untyped end - - # Given a key (as described in +expire_fragment+), returns - # a key array suitable for use in reading, writing, or expiring a - # cached fragment. All keys begin with :views, - # followed by ENV["RAILS_CACHE_ID"] or ENV["RAILS_APP_VERSION"] if set, - # followed by any controller-wide key prefix values, ending - # with the specified +key+ value. - def combined_fragment_cache_key: (untyped key) -> untyped - - # Writes +content+ to the location signified by - # +key+ (see +expire_fragment+ for acceptable formats). - def write_fragment: (untyped key, untyped content, ?untyped? options) -> untyped - - # Reads a cached fragment from the location signified by +key+ - # (see +expire_fragment+ for acceptable formats). - def read_fragment: (untyped key, ?untyped? options) -> (nil | untyped) - - # Check if a cached fragment from the location signified by - # +key+ exists (see +expire_fragment+ for acceptable formats). - def fragment_exist?: (untyped key, ?untyped? options) -> (nil | untyped) - - # Removes fragments from the cache. - # - # +key+ can take one of three forms: - # - # * String - This would normally take the form of a path, like - # pages/45/notes. - # * Hash - Treated as an implicit call to +url_for+, like - # { controller: 'pages', action: 'notes', id: 45} - # * Regexp - Will remove any fragment that matches, so - # %r{pages/\d*/notes} might remove all notes. Make sure you - # don't use anchors in the regex (^ or $) because - # the actual filename matched looks like - # ./cache/filename/path.cache. Note: Regexp expiration is - # only supported on caches that can iterate over all keys (unlike - # memcached). - # - # +options+ is passed through to the cache store's +delete+ - # method (or delete_matched, for Regexp keys). - def expire_fragment: (untyped key, ?untyped? options) -> (nil | untyped) - - def instrument_fragment_cache: (untyped name, untyped key) { () -> untyped } -> untyped - end - end -end - -module AbstractController - module Caching - extend ActiveSupport::Concern - - extend ActiveSupport::Autoload - - module ConfigMethods - def cache_store: () -> untyped - - def cache_store=: (untyped store) -> untyped - - private - - def cache_configured?: () -> untyped - end - - include ConfigMethods - - include AbstractController::Caching::Fragments - extend AbstractController::Caching::Fragments::ClassMethods - - extend ConfigMethods - - module ClassMethods - def view_cache_dependency: () { () -> untyped } -> untyped end - - def view_cache_dependencies: () -> untyped - - private - - def cache: (untyped key, ?::Hash[untyped, untyped] options) { () -> untyped } -> untyped end end module ActionController - # \Caching is a cheap way of speeding up slow applications by keeping the result of - # calculations, renderings, and database calls around for subsequent requests. - # - # You can read more about each approach by clicking the modules below. - # - # Note: To turn off all caching provided by Action Controller, set - # config.action_controller.perform_caching = false - # - # == \Caching stores - # - # All the caching stores from ActiveSupport::Cache are available to be used as backends - # for Action Controller caching. - # - # Configuration examples (FileStore is the default): - # - # config.action_controller.cache_store = :memory_store - # config.action_controller.cache_store = :file_store, '/path/to/cache/directory' - # config.action_controller.cache_store = :mem_cache_store, 'localhost' - # config.action_controller.cache_store = :mem_cache_store, Memcached::Rails.new('localhost:11211') - # config.action_controller.cache_store = MyOwnStore.new('parameter') module Caching - extend ActiveSupport::Autoload - - extend ActiveSupport::Concern - - include AbstractController::Caching extend AbstractController::Caching::ClassMethods extend AbstractController::Caching::Fragments::ClassMethods - - private - - def instrument_payload: (untyped key) -> { controller: untyped, action: untyped, key: untyped } - - def instrument_name: () -> "action_controller" end end diff --git a/gems/actionpack/6.0/actionpack-generated.rbs b/gems/actionpack/6.0/actionpack-generated.rbs index f2f543cc..ae838df4 100644 --- a/gems/actionpack/6.0/actionpack-generated.rbs +++ b/gems/actionpack/6.0/actionpack-generated.rbs @@ -217,6 +217,103 @@ module AbstractController end end +module AbstractController + module Caching + # Fragment caching is used for caching various blocks within + # views without caching the entire action as a whole. This is + # useful when certain elements of an action change frequently or + # depend on complicated state while other parts rarely change or + # can be shared amongst multiple parties. The caching is done using + # the +cache+ helper available in the Action View. See + # ActionView::Helpers::CacheHelper for more information. + # + # While it's strongly recommended that you use key-based cache + # expiration (see links in CacheHelper for more information), + # it is also possible to manually expire caches. For example: + # + # expire_fragment('name_of_cache') + module Fragments + extend ActiveSupport::Concern + + # Given a key (as described in +expire_fragment+), returns + # a key array suitable for use in reading, writing, or expiring a + # cached fragment. All keys begin with :views, + # followed by ENV["RAILS_CACHE_ID"] or ENV["RAILS_APP_VERSION"] if set, + # followed by any controller-wide key prefix values, ending + # with the specified +key+ value. + def combined_fragment_cache_key: (untyped key) -> untyped + + # Writes +content+ to the location signified by + # +key+ (see +expire_fragment+ for acceptable formats). + def write_fragment: (untyped key, untyped content, ?untyped? options) -> untyped + + # Reads a cached fragment from the location signified by +key+ + # (see +expire_fragment+ for acceptable formats). + def read_fragment: (untyped key, ?untyped? options) -> (nil | untyped) + + # Check if a cached fragment from the location signified by + # +key+ exists (see +expire_fragment+ for acceptable formats). + def fragment_exist?: (untyped key, ?untyped? options) -> (nil | untyped) + + # Removes fragments from the cache. + # + # +key+ can take one of three forms: + # + # * String - This would normally take the form of a path, like + # pages/45/notes. + # * Hash - Treated as an implicit call to +url_for+, like + # { controller: 'pages', action: 'notes', id: 45} + # * Regexp - Will remove any fragment that matches, so + # %r{pages/\d*/notes} might remove all notes. Make sure you + # don't use anchors in the regex (^ or $) because + # the actual filename matched looks like + # ./cache/filename/path.cache. Note: Regexp expiration is + # only supported on caches that can iterate over all keys (unlike + # memcached). + # + # +options+ is passed through to the cache store's +delete+ + # method (or delete_matched, for Regexp keys). + def expire_fragment: (untyped key, ?untyped? options) -> (nil | untyped) + + def instrument_fragment_cache: (untyped name, untyped key) { () -> untyped } -> untyped + end + end +end + +module AbstractController + module Caching + extend ActiveSupport::Concern + + extend ActiveSupport::Autoload + + module ConfigMethods + def cache_store: () -> untyped + + def cache_store=: (untyped store) -> untyped + + private + + def cache_configured?: () -> untyped + end + + include ConfigMethods + + include AbstractController::Caching::Fragments + + extend ConfigMethods + + module ClassMethods + def view_cache_dependency: () { () -> untyped } -> untyped + end + + def view_cache_dependencies: () -> untyped + + private + + def cache: (untyped key, ?::Hash[untyped, untyped] options) { () -> untyped } -> untyped + end +end + module AbstractController # = Abstract Controller Callbacks # @@ -306,6 +403,81 @@ module AbstractController end end +module AbstractController + module Helpers + extend ActiveSupport::Concern + + class MissingHelperError < LoadError + def initialize: (untyped error, untyped path) -> untyped + end + + module ClassMethods + # When a class is inherited, wrap its helper module in a new module. + # This ensures that the parent class's module can be changed + # independently of the child class's. + def inherited: (untyped klass) -> untyped + + # Declare a controller method as a helper. For example, the following + # makes the +current_user+ and +logged_in?+ controller methods available + # to the view: + # class ApplicationController < ActionController::Base + # helper_method :current_user, :logged_in? + # + # def current_user + # @current_user ||= User.find_by(id: session[:user]) + # end + # + # def logged_in? + # current_user != nil + # end + # end + # + # In a view: + # <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%> + # + # ==== Parameters + # * method[, method] - A name or names of a method on the controller + # to be made available on the view. + def helper_method: (*untyped meths) -> untyped + + # Clears up all existing helpers in this class, only keeping the helper + # with the same name as this class. + def clear_helpers: () -> untyped + + # Returns a list of modules, normalized from the acceptable kinds of + # helpers with the following behavior: + # + # String or Symbol:: :FooBar or "FooBar" becomes "foo_bar_helper", + # and "foo_bar_helper.rb" is loaded using require_dependency. + # + # Module:: No further processing + # + # After loading the appropriate files, the corresponding modules + # are returned. + # + # ==== Parameters + # * args - An array of helpers + # + # ==== Returns + # * Array - A normalized list of modules for the list of + # helpers provided. + def modules_for_helpers: (untyped args) -> untyped + + private + + # Makes all the (instance) methods in the helper module available to templates + # rendered through this controller. + # + # ==== Parameters + # * module - The module to include into the current helper module + # for the class + def add_template_helper: (untyped mod) -> untyped + + def default_helper_module!: () -> untyped + end + end +end + module AbstractController module Logger # nodoc: @@ -728,6 +900,42 @@ module ActionController end end +module ActionController + # \Caching is a cheap way of speeding up slow applications by keeping the result of + # calculations, renderings, and database calls around for subsequent requests. + # + # You can read more about each approach by clicking the modules below. + # + # Note: To turn off all caching provided by Action Controller, set + # config.action_controller.perform_caching = false + # + # == \Caching stores + # + # All the caching stores from ActiveSupport::Cache are available to be used as backends + # for Action Controller caching. + # + # Configuration examples (FileStore is the default): + # + # config.action_controller.cache_store = :memory_store + # config.action_controller.cache_store = :file_store, '/path/to/cache/directory' + # config.action_controller.cache_store = :mem_cache_store, 'localhost' + # config.action_controller.cache_store = :mem_cache_store, Memcached::Rails.new('localhost:11211') + # config.action_controller.cache_store = MyOwnStore.new('parameter') + module Caching + extend ActiveSupport::Autoload + + extend ActiveSupport::Concern + + include AbstractController::Caching + + private + + def instrument_payload: (untyped key) -> { controller: untyped, action: untyped, key: untyped } + + def instrument_name: () -> "action_controller" + end +end + module ActionController # Override the default form builder for all views rendered by this # controller and any of its descendants. Accepts a subclass of