diff --git a/Rakefile b/Rakefile index 7a30683097..49e8a409d4 100644 --- a/Rakefile +++ b/Rakefile @@ -99,9 +99,9 @@ def generate_src(target_version:) end end -EXISTING_DIRS = %w[classes files].freeze +EXISTING_DIR_AND_FILES = %w[classes files index.html navigation.html].freeze def remove_existing_files(target_dir) - EXISTING_DIRS.each do |dir| + EXISTING_DIR_AND_FILES.each do |dir| rm_rf "#{target_dir}/#{dir}" end end diff --git a/compose.yml b/compose.yml index 9401d3d2bd..2a153dfe97 100644 --- a/compose.yml +++ b/compose.yml @@ -1,6 +1,8 @@ services: app: image: ruby:3.3 + # Use Ruby 2.7 for older builds + # image: ruby:2.7 working_dir: /app volumes: - .:/app diff --git a/src/5.2/classes/AbstractController/Base.html b/src/5.2/classes/AbstractController/Base.html index 3211e46c37..0167353aab 100644 --- a/src/5.2/classes/AbstractController/Base.html +++ b/src/5.2/classes/AbstractController/Base.html @@ -71,11 +71,11 @@
# File actionpack/lib/abstract_controller/base.rb, line 40
+ def abstract!
+ @abstract = true
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 40
-def abstract!
- @abstract = true
-end
- # File actionpack/lib/abstract_controller/base.rb, line 74
+ def action_methods
+ @action_methods ||= begin
+ # All public instance methods of this class, including ancestors
+ methods = (public_instance_methods(true) -
+ # Except for public instance methods of Base and its ancestors
+ internal_methods +
+ # Be sure to include shadowed public instance methods of this class
+ public_instance_methods(false)).uniq.map(&:to_s)
+
+ methods.to_set
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 74
-def action_methods
- @action_methods ||= begin
- # All public instance methods of this class, including ancestors
- methods = (public_instance_methods(true) -
- # Except for public instance methods of Base and its ancestors
- internal_methods +
- # Be sure to include shadowed public instance methods of this class
- public_instance_methods(false)).uniq.map(&:to_s)
-
- methods.to_set
- end
-end
- # File actionpack/lib/abstract_controller/base.rb, line 90
+ def clear_action_methods!
+ @action_methods = nil
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 90
-def clear_action_methods!
- @action_methods = nil
-end
- # File actionpack/lib/abstract_controller/base.rb, line 104
+ def controller_path
+ @controller_path ||= name.sub(/Controller$/, "".freeze).underscore unless anonymous?
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 104
-def controller_path
- @controller_path ||= name.sub(/Controller$/, "".freeze).underscore unless anonymous?
-end
- # File actionpack/lib/abstract_controller/base.rb, line 59
+ def internal_methods
+ controller = self
+
+ controller = controller.superclass until controller.abstract?
+ controller.public_instance_methods(true)
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 59
-def internal_methods
- controller = self
-
- controller = controller.superclass until controller.abstract?
- controller.public_instance_methods(true)
-end
- # File actionpack/lib/abstract_controller/base.rb, line 109
+ def method_added(name)
+ super
+ clear_action_methods!
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 109
-def method_added(name)
- super
- clear_action_methods!
-end
- # File actionpack/lib/abstract_controller/base.rb, line 172
+ def self.supports_path?
+ true
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 172
-def self.supports_path?
- true
-end
- # File actionpack/lib/abstract_controller/base.rb, line 143
+ def action_methods
+ self.class.action_methods
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 143
-def action_methods
- self.class.action_methods
-end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 25
-attr_internal :action_name
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/abstract_controller/base.rb, line 25
+ attr_internal :action_name
-
# File actionpack/lib/abstract_controller/base.rb, line 157
+ def available_action?(action_name)
+ _find_action_name(action_name)
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 157
-def available_action?(action_name)
- _find_action_name(action_name)
-end
- # File actionpack/lib/abstract_controller/base.rb, line 138
+ def controller_path
+ self.class.controller_path
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 138
-def controller_path
- self.class.controller_path
-end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 29
-attr_internal :formats
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/abstract_controller/base.rb, line 29
+ attr_internal :formats
-
# File actionpack/lib/abstract_controller/base.rb, line 164
+ def performed?
+ response_body
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 164
-def performed?
- response_body
-end
- # File actionpack/lib/abstract_controller/base.rb, line 125
+ def process(action, *args)
+ @_action_name = action.to_s
+
+ unless action_name = _find_action_name(@_action_name)
+ raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
+ end
+
+ @_response_body = nil
+
+ process_action(action_name, *args)
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 125
-def process(action, *args)
- @_action_name = action.to_s
-
- unless action_name = _find_action_name(@_action_name)
- raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
- end
-
- @_response_body = nil
-
- process_action(action_name, *args)
-end
- - Source: - -
-# File actionpack/lib/abstract_controller/base.rb, line 21
-attr_internal :response_body
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/abstract_controller/base.rb, line 21
+ attr_internal :response_body
-
# File actionpack/lib/abstract_controller/caching.rb, line 52
+ def view_cache_dependencies
+ self.class._view_cache_dependencies.map { |dep| instance_exec(&dep) }.compact
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching.rb, line 52
-def view_cache_dependencies
- self.class._view_cache_dependencies.map { |dep| instance_exec(&dep) }.compact
-end
- # File actionpack/lib/abstract_controller/caching.rb, line 58
+ def cache(key, options = {}, &block) # :doc:
+ if cache_configured?
+ cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)
+ else
+ yield
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching.rb, line 58
-def cache(key, options = {}, &block) # :doc:
- if cache_configured?
- cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)
- else
- yield
- end
-end
- # File actionpack/lib/abstract_controller/caching.rb, line 47
+ def view_cache_dependency(&dependency)
+ self._view_cache_dependencies += [dependency]
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching.rb, line 47
-def view_cache_dependency(&dependency)
- self._view_cache_dependencies += [dependency]
-end
- # File actionpack/lib/abstract_controller/caching.rb, line 13
+ def cache_store
+ config.cache_store
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching.rb, line 13
-def cache_store
- config.cache_store
-end
- # File actionpack/lib/abstract_controller/caching.rb, line 17
+ def cache_store=(store)
+ config.cache_store = ActiveSupport::Cache.lookup_store(store)
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching.rb, line 17
-def cache_store=(store)
- config.cache_store = ActiveSupport::Cache.lookup_store(store)
-end
- # File actionpack/lib/abstract_controller/caching/fragments.rb, line 88
+ def combined_fragment_cache_key(key)
+ head = self.class.fragment_cache_keys.map { |k| instance_exec(&k) }
+ tail = key.is_a?(Hash) ? url_for(key).split("://").last : key
+ [ :views, (ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]), *head, *tail ].compact
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching/fragments.rb, line 88
-def combined_fragment_cache_key(key)
- head = self.class.fragment_cache_keys.map { |k| instance_exec(&k) }
- tail = key.is_a?(Hash) ? url_for(key).split("://").last : key
- [ :views, (ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]), *head, *tail ].compact
-end
- # File actionpack/lib/abstract_controller/caching/fragments.rb, line 148
+ def expire_fragment(key, options = nil)
+ return unless cache_configured?
+ key = combined_fragment_cache_key(key) unless key.is_a?(Regexp)
+
+ instrument_fragment_cache :expire_fragment, key do
+ if key.is_a?(Regexp)
+ cache_store.delete_matched(key, options)
+ else
+ cache_store.delete(key, options)
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching/fragments.rb, line 148
-def expire_fragment(key, options = nil)
- return unless cache_configured?
- key = combined_fragment_cache_key(key) unless key.is_a?(Regexp)
-
- instrument_fragment_cache :expire_fragment, key do
- if key.is_a?(Regexp)
- cache_store.delete_matched(key, options)
- else
- cache_store.delete(key, options)
- end
- end
-end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching/fragments.rb, line 69
- def fragment_cache_key(key)
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- Calling fragment_cache_key directly is deprecated and will be removed in Rails 6.0.
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/abstract_controller/caching/fragments.rb, line 69
+ def fragment_cache_key(key)
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ Calling fragment_cache_key directly is deprecated and will be removed in Rails 6.0.
All fragment accessors now use the combined_fragment_cache_key method that retains the key as an array,
such that the caching stores can interrogate the parts for cache versions used in
recyclable cache keys.
-
MSG
+ MSG
- head = self.class.fragment_cache_keys.map { |k| instance_exec(&k) }
- tail = key.is_a?(Hash) ? url_for(key).split("://").last : key
- ActiveSupport::Cache.expand_cache_key([*head, *tail], :views)
- end
- # File actionpack/lib/abstract_controller/caching/fragments.rb, line 121
+ def fragment_exist?(key, options = nil)
+ return unless cache_configured?
+ key = combined_fragment_cache_key(key)
+
+ instrument_fragment_cache :exist_fragment?, key do
+ cache_store.exist?(key, options)
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching/fragments.rb, line 121
-def fragment_exist?(key, options = nil)
- return unless cache_configured?
- key = combined_fragment_cache_key(key)
-
- instrument_fragment_cache :exist_fragment?, key do
- cache_store.exist?(key, options)
- end
-end
- # File actionpack/lib/abstract_controller/caching/fragments.rb, line 109
+ def read_fragment(key, options = nil)
+ return unless cache_configured?
+
+ key = combined_fragment_cache_key(key)
+ instrument_fragment_cache :read_fragment, key do
+ result = cache_store.read(key, options)
+ result.respond_to?(:html_safe) ? result.html_safe : result
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching/fragments.rb, line 109
-def read_fragment(key, options = nil)
- return unless cache_configured?
-
- key = combined_fragment_cache_key(key)
- instrument_fragment_cache :read_fragment, key do
- result = cache_store.read(key, options)
- result.respond_to?(:html_safe) ? result.html_safe : result
- end
-end
- # File actionpack/lib/abstract_controller/caching/fragments.rb, line 96
+ def write_fragment(key, content, options = nil)
+ return content unless cache_configured?
+
+ key = combined_fragment_cache_key(key)
+ instrument_fragment_cache :write_fragment, key do
+ content = content.to_str
+ cache_store.write(key, content, options)
+ end
+ content
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching/fragments.rb, line 96
-def write_fragment(key, content, options = nil)
- return content unless cache_configured?
-
- key = combined_fragment_cache_key(key)
- instrument_fragment_cache :write_fragment, key do
- content = content.to_str
- cache_store.write(key, content, options)
- end
- content
-end
- # File actionpack/lib/abstract_controller/caching/fragments.rb, line 58
+ def fragment_cache_key(value = nil, &key)
+ self.fragment_cache_keys += [key || -> { value }]
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/caching/fragments.rb, line 58
-def fragment_cache_key(value = nil, &key)
- self.fragment_cache_keys += [key || -> { value }]
-end
- # File actionpack/lib/abstract_controller/callbacks.rb, line 40
+ def process_action(*args)
+ run_callbacks(:process_action) do
+ super
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 40
-def process_action(*args)
- run_callbacks(:process_action) do
- super
- end
-end
- # File actionpack/lib/abstract_controller/callbacks.rb, line 91
+ def _insert_callbacks(callbacks, block = nil)
+ options = callbacks.extract_options!
+ _normalize_callback_options(options)
+ callbacks.push(block) if block
+ callbacks.each do |callback|
+ yield callback, options
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 91
-def _insert_callbacks(callbacks, block = nil)
- options = callbacks.extract_options!
- _normalize_callback_options(options)
- callbacks.push(block) if block
- callbacks.each do |callback|
- yield callback, options
- end
-end
- # File actionpack/lib/abstract_controller/callbacks.rb, line 66
+ def _normalize_callback_options(options)
+ _normalize_callback_option(options, :only, :if)
+ _normalize_callback_option(options, :except, :unless)
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 66
-def _normalize_callback_options(options)
- _normalize_callback_option(options, :only, :if)
- _normalize_callback_option(options, :except, :unless)
-end
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 129
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 150
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 178
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 122
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 157
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 101
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 136
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 164
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 108
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 143
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 171
-
- - Source: - -
-# File actionpack/lib/abstract_controller/callbacks.rb, line 115
-
- - Source: - -
-# File actionpack/lib/abstract_controller/collector.rb, line 7
- def self.generate_method_for_mime(mime)
- sym = mime.is_a?(Symbol) ? mime : mime.to_sym
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
- def #{sym}(*args, &block)
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/abstract_controller/collector.rb, line 7
+ def self.generate_method_for_mime(mime)
+ sym = mime.is_a?(Symbol) ? mime : mime.to_sym
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def #{sym}(*args, &block)
custom(Mime[:#{sym}], *args, &block)
end
-
RUBY
- end
- # File actionpack/lib/abstract_controller/rendering.rb, line 12
+ def initialize(message = nil)
+ super(message || DEFAULT_MESSAGE)
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/rendering.rb, line 12
-def initialize(message = nil)
- super(message || DEFAULT_MESSAGE)
-end
- # File actionpack/lib/abstract_controller/helpers.rb, line 117
+ def clear_helpers
+ inherited_helper_methods = _helper_methods
+ self._helpers = Module.new
+ self._helper_methods = Array.new
+
+ inherited_helper_methods.each { |meth| helper_method meth }
+ default_helper_module! unless anonymous?
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/helpers.rb, line 117
-def clear_helpers
- inherited_helper_methods = _helper_methods
- self._helpers = Module.new
- self._helper_methods = Array.new
-
- inherited_helper_methods.each { |meth| helper_method meth }
- default_helper_module! unless anonymous?
-end
- # File actionpack/lib/abstract_controller/helpers.rb, line 107
+ def helper(*args, &block)
+ modules_for_helpers(args).each do |mod|
+ add_template_helper(mod)
+ end
+
+ _helpers.module_eval(&block) if block_given?
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/helpers.rb, line 107
-def helper(*args, &block)
- modules_for_helpers(args).each do |mod|
- add_template_helper(mod)
- end
-
- _helpers.module_eval(&block) if block_given?
-end
- - Source: - -
-# File actionpack/lib/abstract_controller/helpers.rb, line 60
- def helper_method(*meths)
- meths.flatten!
- self._helper_methods += meths
-
- meths.each do |meth|
- _helpers.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
- def #{meth}(*args, &blk) # def current_user(*args, &blk)
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/abstract_controller/helpers.rb, line 60
+ def helper_method(*meths)
+ meths.flatten!
+ self._helper_methods += meths
+
+ meths.each do |meth|
+ _helpers.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
+ def #{meth}(*args, &blk) # def current_user(*args, &blk)
controller.send(%(#{meth}), *args, &blk) # controller.send(:current_user, *args, &blk)
end # end
-
ruby_eval
- end
- end
- # File actionpack/lib/abstract_controller/helpers.rb, line 32
+ def inherited(klass)
+ helpers = _helpers
+ klass._helpers = Module.new { include helpers }
+ klass.class_eval { default_helper_module! } unless klass.anonymous?
+ super
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/helpers.rb, line 32
-def inherited(klass)
- helpers = _helpers
- klass._helpers = Module.new { include helpers }
- klass.class_eval { default_helper_module! } unless klass.anonymous?
- super
-end
- # File actionpack/lib/abstract_controller/helpers.rb, line 143
+ def modules_for_helpers(args)
+ args.flatten.map! do |arg|
+ case arg
+ when String, Symbol
+ file_name = "#{arg.to_s.underscore}_helper"
+ begin
+ require_dependency(file_name)
+ rescue LoadError => e
+ raise AbstractController::Helpers::MissingHelperError.new(e, file_name)
+ end
+
+ mod_name = file_name.camelize
+ begin
+ mod_name.constantize
+ rescue LoadError
+ # dependencies.rb gives a similar error message but its wording is
+ # not as clear because it mentions autoloading. To the user all it
+ # matters is that a helper module couldn't be loaded, autoloading
+ # is an internal mechanism that should not leak.
+ raise NameError, "Couldn't find #{mod_name}, expected it to be defined in helpers/#{file_name}.rb"
+ end
+ when Module
+ arg
+ else
+ raise ArgumentError, "helper must be a String, Symbol, or Module"
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/helpers.rb, line 143
-def modules_for_helpers(args)
- args.flatten.map! do |arg|
- case arg
- when String, Symbol
- file_name = "#{arg.to_s.underscore}_helper"
- begin
- require_dependency(file_name)
- rescue LoadError => e
- raise AbstractController::Helpers::MissingHelperError.new(e, file_name)
- end
-
- mod_name = file_name.camelize
- begin
- mod_name.constantize
- rescue LoadError
- # dependencies.rb gives a similar error message but its wording is
- # not as clear because it mentions autoloading. To the user all it
- # matters is that a helper module couldn't be loaded, autoloading
- # is an internal mechanism that should not leak.
- raise NameError, "Couldn't find #{mod_name}, expected it to be defined in helpers/#{file_name}.rb"
- end
- when Module
- arg
- else
- raise ArgumentError, "helper must be a String, Symbol, or Module"
- end
- end
-end
- # File actionpack/lib/abstract_controller/helpers.rb, line 15
+ def initialize(error, path)
+ @error = error
+ @path = "helpers/#{path}.rb"
+ set_backtrace error.backtrace
+
+ if error.path =~ /^#{path}(\.rb)?$/
+ super("Missing helper file helpers/%s.rb" % path)
+ else
+ raise error
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/helpers.rb, line 15
-def initialize(error, path)
- @error = error
- @path = "helpers/#{path}.rb"
- set_backtrace error.backtrace
-
- if error.path =~ /^#{path}(\.rb)?$/
- super("Missing helper file helpers/%s.rb" % path)
- else
- raise error
- end
-end
- # File actionpack/lib/abstract_controller/railties/routes_helpers.rb, line 6
+ def self.with(routes, include_path_helpers = true)
+ Module.new do
+ define_method(:inherited) do |klass|
+ super(klass)
+ if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_routes_url_helpers) }
+ klass.include(namespace.railtie_routes_url_helpers(include_path_helpers))
+ else
+ klass.include(routes.url_helpers(include_path_helpers))
+ end
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/railties/routes_helpers.rb, line 6
-def self.with(routes, include_path_helpers = true)
- Module.new do
- define_method(:inherited) do |klass|
- super(klass)
- if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_routes_url_helpers) }
- klass.include(namespace.railtie_routes_url_helpers(include_path_helpers))
- else
- klass.include(routes.url_helpers(include_path_helpers))
- end
- end
- end
-end
- # File actionpack/lib/abstract_controller/rendering.rb, line 23
+ def render(*args, &block)
+ options = _normalize_render(*args, &block)
+ rendered_body = render_to_body(options)
+ if options[:html]
+ _set_html_content_type
+ else
+ _set_rendered_content_type rendered_format
+ end
+ self.response_body = rendered_body
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/rendering.rb, line 23
-def render(*args, &block)
- options = _normalize_render(*args, &block)
- rendered_body = render_to_body(options)
- if options[:html]
- _set_html_content_type
- else
- _set_rendered_content_type rendered_format
- end
- self.response_body = rendered_body
-end
- # File actionpack/lib/abstract_controller/rendering.rb, line 50
+ def render_to_body(options = {})
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/rendering.rb, line 50
-def render_to_body(options = {})
-end
- # File actionpack/lib/abstract_controller/rendering.rb, line 44
+ def render_to_string(*args, &block)
+ options = _normalize_render(*args, &block)
+ render_to_body(options)
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/rendering.rb, line 44
-def render_to_string(*args, &block)
- options = _normalize_render(*args, &block)
- render_to_body(options)
-end
- # File actionpack/lib/abstract_controller/rendering.rb, line 54
+ def rendered_format
+ Mime[:text]
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/rendering.rb, line 54
-def rendered_format
- Mime[:text]
-end
- # File actionpack/lib/abstract_controller/rendering.rb, line 64
+ def view_assigns
+ protected_vars = _protected_ivars
+ variables = instance_variables
+
+ variables.reject! { |s| protected_vars.include? s }
+ variables.each_with_object({}) { |name, hash|
+ hash[name.slice(1, name.length)] = instance_variable_get(name)
+ }
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/rendering.rb, line 64
-def view_assigns
- protected_vars = _protected_ivars
- variables = instance_variables
-
- variables.reject! { |s| protected_vars.include? s }
- variables.each_with_object({}) { |name, hash|
- hash[name.slice(1, name.length)] = instance_variable_get(name)
- }
-end
- # File actionpack/lib/abstract_controller/rendering.rb, line 78
+ def _normalize_args(action = nil, options = {}) # :doc:
+ if action.respond_to?(:permitted?)
+ if action.permitted?
+ action
+ else
+ raise ArgumentError, "render parameters are not permitted"
+ end
+ elsif action.is_a?(Hash)
+ action
+ else
+ options
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/rendering.rb, line 78
-def _normalize_args(action = nil, options = {}) # :doc:
- if action.respond_to?(:permitted?)
- if action.permitted?
- action
- else
- raise ArgumentError, "render parameters are not permitted"
- end
- elsif action.is_a?(Hash)
- action
- else
- options
- end
-end
- # File actionpack/lib/abstract_controller/rendering.rb, line 93
+ def _normalize_options(options) # :doc:
+ options
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/rendering.rb, line 93
-def _normalize_options(options) # :doc:
- options
-end
- # File actionpack/lib/abstract_controller/rendering.rb, line 98
+ def _process_options(options) # :doc:
+ options
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/rendering.rb, line 98
-def _process_options(options) # :doc:
- options
-end
- # File actionpack/lib/abstract_controller/translation.rb, line 26
+ def localize(*args)
+ I18n.localize(*args)
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/translation.rb, line 26
-def localize(*args)
- I18n.localize(*args)
-end
- # File actionpack/lib/abstract_controller/translation.rb, line 13
+ def translate(key, options = {})
+ if key.to_s.first == "."
+ path = controller_path.tr("/", ".")
+ defaults = [:"#{path}#{key}"]
+ defaults << options[:default] if options[:default]
+ options[:default] = defaults.flatten
+ key = "#{path}.#{action_name}#{key}"
+ end
+ I18n.translate(key, options)
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/translation.rb, line 13
-def translate(key, options = {})
- if key.to_s.first == "."
- path = controller_path.tr("/", ".")
- defaults = [:"#{path}#{key}"]
- defaults << options[:default] if options[:default]
- options[:default] = defaults.flatten
- key = "#{path}.#{action_name}#{key}"
- end
- I18n.translate(key, options)
-end
- # File actionpack/lib/abstract_controller/url_for.rb, line 14
+ def _routes
+ raise "In order to use #url_for, you must include routing helpers explicitly. " \
+ "For instance, `include Rails.application.routes.url_helpers`."
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/url_for.rb, line 14
-def _routes
- raise "In order to use #url_for, you must include routing helpers explicitly. " \
- "For instance, `include Rails.application.routes.url_helpers`."
-end
- # File actionpack/lib/abstract_controller/url_for.rb, line 20
+ def _routes
+ nil
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/url_for.rb, line 20
-def _routes
- nil
-end
- # File actionpack/lib/abstract_controller/url_for.rb, line 24
+ def action_methods
+ @action_methods ||= begin
+ if _routes
+ super - _routes.named_routes.helper_names
+ else
+ super
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/abstract_controller/url_for.rb, line 24
-def action_methods
- @action_methods ||= begin
- if _routes
- super - _routes.named_routes.helper_names
- else
- super
- end
- end
-end
- # File actioncable/lib/action_cable/gem_version.rb, line 5
+ def self.gem_version
+ Gem::Version.new VERSION::STRING
+ end
- - Source: - -
-# File actioncable/lib/action_cable/gem_version.rb, line 5
-def self.gem_version
- Gem::Version.new VERSION::STRING
-end
- # File actioncable/lib/action_cable/version.rb, line 7
+ def self.version
+ gem_version
+ end
- - Source: - -
-# File actioncable/lib/action_cable/version.rb, line 7
-def self.version
- gem_version
-end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 115
-def action_methods
- @action_methods ||= begin
- # All public instance methods of this class, including ancestors
- methods = (public_instance_methods(true) -
- # Except for public instance methods of Base and its ancestors
- ActionCable::Channel::Base.public_instance_methods(true) +
- # Be sure to include shadowed public instance methods of this class
- public_instance_methods(false)).uniq.map(&:to_s)
- methods.to_set
- end
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 115
+ def action_methods
+ @action_methods ||= begin
+ # All public instance methods of this class, including ancestors
+ methods = (public_instance_methods(true) -
+ # Except for public instance methods of Base and its ancestors
+ ActionCable::Channel::Base.public_instance_methods(true) +
+ # Be sure to include shadowed public instance methods of this class
+ public_instance_methods(false)).uniq.map(&:to_s)
+ methods.to_set
+ end
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 142
-def initialize(connection, identifier, params = {})
- @connection = connection
- @identifier = identifier
- @params = params
+
+
+
+ 📝 Source code
+
- # When a channel is streaming via pubsub, we want to delay the confirmation
- # transmission until pubsub subscription is confirmed.
- #
- # The counter starts at 1 because it's awaiting a call to #subscribe_to_channel
- @defer_subscription_confirmation_counter = Concurrent::AtomicFixnum.new(1)
+ # File actioncable/lib/action_cable/channel/base.rb, line 142
+ def initialize(connection, identifier, params = {})
+ @connection = connection
+ @identifier = identifier
+ @params = params
- @reject_subscription = nil
- @subscription_confirmation_sent = nil
+ # When a channel is streaming via pubsub, we want to delay the confirmation
+ # transmission until pubsub subscription is confirmed.
+ #
+ # The counter starts at 1 because it's awaiting a call to #subscribe_to_channel
+ @defer_subscription_confirmation_counter = Concurrent::AtomicFixnum.new(1)
- delegate_connection_identifiers
-end
-
# File actioncable/lib/action_cable/channel/base.rb, line 131
+ def clear_action_methods! # :doc:
+ @action_methods = nil
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 131
-def clear_action_methods! # :doc:
- @action_methods = nil
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 136
+ def method_added(name) # :doc:
+ super
+ clear_action_methods!
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 136
-def method_added(name) # :doc:
- super
- clear_action_methods!
-end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 162
-def perform_action(data)
- action = extract_action(data)
+
+
+
+ 📝 Source code
+
- if processable_action?(action)
- payload = { channel_class: self.class.name, action: action, data: data }
- ActiveSupport::Notifications.instrument("perform_action.action_cable", payload) do
- dispatch_action(action, data)
- end
- else
- logger.error "Unable to process #{action_signature(action, data)}"
- end
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 162
+ def perform_action(data)
+ action = extract_action(data)
+
+ if processable_action?(action)
+ payload = { channel_class: self.class.name, action: action, data: data }
+ ActiveSupport::Notifications.instrument("perform_action.action_cable", payload) do
+ dispatch_action(action, data)
+ end
+ else
+ logger.error "Unable to process #{action_signature(action, data)}"
+ end
+ end
+
+ 🔎 See on GitHub
+
+
+
+
- Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 177
-def subscribe_to_channel
- run_callbacks :subscribe do
- subscribed
- end
+
+
+
+ 📝 Source code
+
- reject_subscription if subscription_rejected?
- ensure_confirmation_sent
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 177
+ def subscribe_to_channel
+ run_callbacks :subscribe do
+ subscribed
+ end
+
+ reject_subscription if subscription_rejected?
+ ensure_confirmation_sent
+ end
+
+ 🔎 See on GitHub
+
+
+
+
# File actioncable/lib/action_cable/channel/base.rb, line 226
+ def defer_subscription_confirmation! # :doc:
+ @defer_subscription_confirmation_counter.increment
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 226
-def defer_subscription_confirmation! # :doc:
- @defer_subscription_confirmation_counter.increment
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 230
+ def defer_subscription_confirmation? # :doc:
+ @defer_subscription_confirmation_counter.value > 0
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 230
-def defer_subscription_confirmation? # :doc:
- @defer_subscription_confirmation_counter.value > 0
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 220
+ def ensure_confirmation_sent # :doc:
+ return if subscription_rejected?
+ @defer_subscription_confirmation_counter.decrement
+ transmit_subscription_confirmation unless defer_subscription_confirmation?
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 220
-def ensure_confirmation_sent # :doc:
- return if subscription_rejected?
- @defer_subscription_confirmation_counter.decrement
- transmit_subscription_confirmation unless defer_subscription_confirmation?
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 238
+ def reject # :doc:
+ @reject_subscription = true
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 238
-def reject # :doc:
- @reject_subscription = true
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 197
+ def subscribed # :doc:
+ # Override in subclasses
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 197
-def subscribed # :doc:
- # Override in subclasses
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 234
+ def subscription_confirmation_sent? # :doc:
+ @subscription_confirmation_sent
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 234
-def subscription_confirmation_sent? # :doc:
- @subscription_confirmation_sent
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 242
+ def subscription_rejected? # :doc:
+ @reject_subscription
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 242
-def subscription_rejected? # :doc:
- @reject_subscription
-end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 209
-def transmit(data, via: nil) # :doc:
- status = "#{self.class.name} transmitting #{data.inspect.truncate(300)}"
- status += " (via #{via})" if via
- logger.debug(status)
+
+
+
+ 📝 Source code
+
- payload = { channel_class: self.class.name, data: data, via: via }
- ActiveSupport::Notifications.instrument("transmit.action_cable", payload) do
- connection.transmit identifier: @identifier, message: data
- end
-end
- # File actioncable/lib/action_cable/channel/base.rb, line 209
+ def transmit(data, via: nil) # :doc:
+ status = "#{self.class.name} transmitting #{data.inspect.truncate(300)}"
+ status += " (via #{via})" if via
+ logger.debug(status)
+
+ payload = { channel_class: self.class.name, data: data, via: via }
+ ActiveSupport::Notifications.instrument("transmit.action_cable", payload) do
+ connection.transmit identifier: @identifier, message: data
+ end
+ end
+
+ 🔎 See on GitHub
+
+
+
+
# File actioncable/lib/action_cable/channel/base.rb, line 203
+ def unsubscribed # :doc:
+ # Override in subclasses
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/base.rb, line 203
-def unsubscribed # :doc:
- # Override in subclasses
-end
- # File actioncable/lib/action_cable/channel/broadcasting.rb, line 14
+ def broadcast_to(model, message)
+ ActionCable.server.broadcast(broadcasting_for([ channel_name, model ]), message)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/broadcasting.rb, line 14
-def broadcast_to(model, message)
- ActionCable.server.broadcast(broadcasting_for([ channel_name, model ]), message)
-end
- # File actioncable/lib/action_cable/channel/callbacks.rb, line 21
+ def after_subscribe(*methods, &block)
+ set_callback(:subscribe, :after, *methods, &block)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/callbacks.rb, line 21
-def after_subscribe(*methods, &block)
- set_callback(:subscribe, :after, *methods, &block)
-end
- # File actioncable/lib/action_cable/channel/callbacks.rb, line 30
+ def after_unsubscribe(*methods, &block)
+ set_callback(:unsubscribe, :after, *methods, &block)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/callbacks.rb, line 30
-def after_unsubscribe(*methods, &block)
- set_callback(:unsubscribe, :after, *methods, &block)
-end
- # File actioncable/lib/action_cable/channel/callbacks.rb, line 17
+ def before_subscribe(*methods, &block)
+ set_callback(:subscribe, :before, *methods, &block)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/callbacks.rb, line 17
-def before_subscribe(*methods, &block)
- set_callback(:subscribe, :before, *methods, &block)
-end
- # File actioncable/lib/action_cable/channel/callbacks.rb, line 26
+ def before_unsubscribe(*methods, &block)
+ set_callback(:unsubscribe, :before, *methods, &block)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/callbacks.rb, line 26
-def before_unsubscribe(*methods, &block)
- set_callback(:unsubscribe, :before, *methods, &block)
-end
- # File actioncable/lib/action_cable/channel/naming.rb, line 16
+ def channel_name
+ @channel_name ||= name.sub(/Channel$/, "").gsub("::", ":").underscore
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/naming.rb, line 16
-def channel_name
- @channel_name ||= name.sub(/Channel$/, "").gsub("::", ":").underscore
-end
- # File actioncable/lib/action_cable/channel/periodic_timers.rb, line 31
+ def periodically(callback_or_method_name = nil, every:, &block)
+ callback =
+ if block_given?
+ raise ArgumentError, "Pass a block or provide a callback arg, not both" if callback_or_method_name
+ block
+ else
+ case callback_or_method_name
+ when Proc
+ callback_or_method_name
+ when Symbol
+ -> { __send__ callback_or_method_name }
+ else
+ raise ArgumentError, "Expected a Symbol method name or a Proc, got #{callback_or_method_name.inspect}"
+ end
+ end
+
+ unless every.kind_of?(Numeric) && every > 0
+ raise ArgumentError, "Expected every: to be a positive number of seconds, got #{every.inspect}"
+ end
+
+ self.periodic_timers += [[ callback, every: every ]]
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/periodic_timers.rb, line 31
-def periodically(callback_or_method_name = nil, every:, &block)
- callback =
- if block_given?
- raise ArgumentError, "Pass a block or provide a callback arg, not both" if callback_or_method_name
- block
- else
- case callback_or_method_name
- when Proc
- callback_or_method_name
- when Symbol
- -> { __send__ callback_or_method_name }
- else
- raise ArgumentError, "Expected a Symbol method name or a Proc, got #{callback_or_method_name.inspect}"
- end
- end
-
- unless every.kind_of?(Numeric) && every > 0
- raise ArgumentError, "Expected every: to be a positive number of seconds, got #{every.inspect}"
- end
-
- self.periodic_timers += [[ callback, every: every ]]
-end
- # File actioncable/lib/action_cable/channel/streams.rb, line 106
+ def stop_all_streams
+ streams.each do |broadcasting, callback|
+ pubsub.unsubscribe broadcasting, callback
+ logger.info "#{self.class.name} stopped streaming from #{broadcasting}"
+ end.clear
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/streams.rb, line 106
-def stop_all_streams
- streams.each do |broadcasting, callback|
- pubsub.unsubscribe broadcasting, callback
- logger.info "#{self.class.name} stopped streaming from #{broadcasting}"
- end.clear
-end
- # File actioncable/lib/action_cable/channel/streams.rb, line 101
+ def stream_for(model, callback = nil, coder: nil, &block)
+ stream_from(broadcasting_for([ channel_name, model ]), callback || block, coder: coder)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/streams.rb, line 101
-def stream_for(model, callback = nil, coder: nil, &block)
- stream_from(broadcasting_for([ channel_name, model ]), callback || block, coder: coder)
-end
- # File actioncable/lib/action_cable/channel/streams.rb, line 76
+ def stream_from(broadcasting, callback = nil, coder: nil, &block)
+ broadcasting = String(broadcasting)
+
+ # Don't send the confirmation until pubsub#subscribe is successful
+ defer_subscription_confirmation!
+
+ # Build a stream handler by wrapping the user-provided callback with
+ # a decoder or defaulting to a JSON-decoding retransmitter.
+ handler = worker_pool_stream_handler(broadcasting, callback || block, coder: coder)
+ streams << [ broadcasting, handler ]
+
+ connection.server.event_loop.post do
+ pubsub.subscribe(broadcasting, handler, lambda do
+ ensure_confirmation_sent
+ logger.info "#{self.class.name} is streaming from #{broadcasting}"
+ end)
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/channel/streams.rb, line 76
-def stream_from(broadcasting, callback = nil, coder: nil, &block)
- broadcasting = String(broadcasting)
-
- # Don't send the confirmation until pubsub#subscribe is successful
- defer_subscription_confirmation!
-
- # Build a stream handler by wrapping the user-provided callback with
- # a decoder or defaulting to a JSON-decoding retransmitter.
- handler = worker_pool_stream_handler(broadcasting, callback || block, coder: coder)
- streams << [ broadcasting, handler ]
-
- connection.server.event_loop.post do
- pubsub.subscribe(broadcasting, handler, lambda do
- ensure_confirmation_sent
- logger.info "#{self.class.name} is streaming from #{broadcasting}"
- end)
- end
-end
- # File actioncable/lib/action_cable/connection/authorization.rb, line 9
+ def reject_unauthorized_connection
+ logger.error "An unauthorized connection attempt was rejected"
+ raise UnauthorizedError
+ end
- - Source: - -
- -# File actioncable/lib/action_cable/connection/base.rb, line 53
+ def initialize(server, env, coder: ActiveSupport::JSON)
+ @server, @env, @coder = server, env, coder
+
+ @worker_pool = server.worker_pool
+ @logger = new_tagged_logger
+
+ @websocket = ActionCable::Connection::WebSocket.new(env, self, event_loop)
+ @subscriptions = ActionCable::Connection::Subscriptions.new(self)
+ @message_buffer = ActionCable::Connection::MessageBuffer.new(self)
+
+ @_internal_subscriptions = nil
+ @started_at = Time.now
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/base.rb, line 53
-def initialize(server, env, coder: ActiveSupport::JSON)
- @server, @env, @coder = server, env, coder
-
- @worker_pool = server.worker_pool
- @logger = new_tagged_logger
-
- @websocket = ActionCable::Connection::WebSocket.new(env, self, event_loop)
- @subscriptions = ActionCable::Connection::Subscriptions.new(self)
- @message_buffer = ActionCable::Connection::MessageBuffer.new(self)
-
- @_internal_subscriptions = nil
- @started_at = Time.now
-end
- # File actioncable/lib/action_cable/connection/base.rb, line 118
+ def beat
+ transmit type: ActionCable::INTERNAL[:message_types][:ping], message: Time.now.to_i
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/base.rb, line 118
-def beat
- transmit type: ActionCable::INTERNAL[:message_types][:ping], message: Time.now.to_i
-end
- # File actioncable/lib/action_cable/connection/base.rb, line 98
+ def close
+ websocket.close
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/base.rb, line 98
-def close
- websocket.close
-end
- # File actioncable/lib/action_cable/connection/base.rb, line 103
+ def send_async(method, *arguments)
+ worker_pool.async_invoke(self, method, *arguments)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/base.rb, line 103
-def send_async(method, *arguments)
- worker_pool.async_invoke(self, method, *arguments)
-end
- # File actioncable/lib/action_cable/connection/base.rb, line 109
+ def statistics
+ {
+ identifier: connection_identifier,
+ started_at: @started_at,
+ subscriptions: subscriptions.identifiers,
+ request_id: @env["action_dispatch.request_id"]
+ }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/base.rb, line 109
-def statistics
- {
- identifier: connection_identifier,
- started_at: @started_at,
- subscriptions: subscriptions.identifiers,
- request_id: @env["action_dispatch.request_id"]
- }
-end
- # File actioncable/lib/action_cable/connection/base.rb, line 155
+ def cookies # :doc:
+ request.cookie_jar
+ end
- - Source: - -
- -# File actioncable/lib/action_cable/connection/base.rb, line 147
+ def request # :doc:
+ @request ||= begin
+ environment = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
+ ActionDispatch::Request.new(environment || env)
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/base.rb, line 147
-def request # :doc:
- @request ||= begin
- environment = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
- ActionDispatch::Request.new(environment || env)
- end
-end
- # File actioncable/lib/action_cable/connection/identification.rb, line 27
+ def connection_identifier
+ unless defined? @connection_identifier
+ @connection_identifier = connection_gid identifiers.map { |id| instance_variable_get("@#{id}") }.compact
+ end
+
+ @connection_identifier
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/identification.rb, line 27
-def connection_identifier
- unless defined? @connection_identifier
- @connection_identifier = connection_gid identifiers.map { |id| instance_variable_get("@#{id}") }.compact
- end
-
- @connection_identifier
-end
- # File actioncable/lib/action_cable/connection/identification.rb, line 20
+ def identified_by(*identifiers)
+ Array(identifiers).each { |identifier| attr_accessor identifier }
+ self.identifiers += identifiers
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/identification.rb, line 20
-def identified_by(*identifiers)
- Array(identifiers).each { |identifier| attr_accessor identifier }
- self.identifiers += identifiers
-end
- # File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 9
+ def initialize
+ @nio = @executor = @thread = nil
+ @map = {}
+ @stopping = false
+ @todo = Queue.new
+
+ @spawn_mutex = Mutex.new
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 9
-def initialize
- @nio = @executor = @thread = nil
- @map = {}
- @stopping = false
- @todo = Queue.new
-
- @spawn_mutex = Mutex.new
-end
- # File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 29
+ def attach(io, stream)
+ @todo << lambda do
+ @map[io] = @nio.register(io, :r)
+ @map[io].value = stream
+ end
+ wakeup
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 29
-def attach(io, stream)
- @todo << lambda do
- @map[io] = @nio.register(io, :r)
- @map[io].value = stream
- end
- wakeup
-end
- # File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 37
+ def detach(io, stream)
+ @todo << lambda do
+ @nio.deregister io
+ @map.delete io
+ io.close
+ end
+ wakeup
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 37
-def detach(io, stream)
- @todo << lambda do
- @nio.deregister io
- @map.delete io
- io.close
- end
- wakeup
-end
- # File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 22
+ def post(task = nil, &block)
+ task ||= block
+
+ spawn
+ @executor << task
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 22
-def post(task = nil, &block)
- task ||= block
-
- spawn
- @executor << task
-end
- # File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 55
+ def stop
+ @stopping = true
+ wakeup if @nio
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 55
-def stop
- @stopping = true
- wakeup if @nio
-end
- # File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 18
+ def timer(interval, &block)
+ Concurrent::TimerTask.new(execution_interval: interval, &block).tap(&:execute)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 18
-def timer(interval, &block)
- Concurrent::TimerTask.new(execution_interval: interval, &block).tap(&:execute)
-end
- # File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 46
+ def writes_pending(io)
+ @todo << lambda do
+ if monitor = @map[io]
+ monitor.interests = :rw
+ end
+ end
+ wakeup
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/stream_event_loop.rb, line 46
-def writes_pending(io)
- @todo << lambda do
- if monitor = @map[io]
- monitor.interests = :rw
- end
- end
- wakeup
-end
- # File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 11
+ def initialize(logger, tags:)
+ @logger = logger
+ @tags = tags.flatten
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 11
-def initialize(logger, tags:)
- @logger = logger
- @tags = tags.flatten
-end
- # File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 16
+ def add_tags(*tags)
+ @tags += tags.flatten
+ @tags = @tags.uniq
+ end
- - Source: - -
- -# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 21
+ def tag(logger)
+ if logger.respond_to?(:tagged)
+ current_tags = tags - logger.formatter.current_tags
+ logger.tagged(*current_tags) { yield }
+ else
+ yield
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 21
-def tag(logger)
- if logger.respond_to?(:tagged)
- current_tags = tags - logger.formatter.current_tags
- logger.tagged(*current_tags) { yield }
- else
- yield
- end
-end
- # File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 37
+ def log(type, message) # :doc:
+ tag(@logger) { @logger.send type, message }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 37
-def log(type, message) # :doc:
- tag(@logger) { @logger.send type, message }
-end
- # File actioncable/lib/action_cable/helpers/action_cable_helper.rb, line 33
+ def action_cable_meta_tag
+ tag "meta", name: "action-cable-url", content: (
+ ActionCable.server.config.url ||
+ ActionCable.server.config.mount_path ||
+ raise("No Action Cable URL configured -- please configure this at config.action_cable.url")
+ )
+ end
- - Source: - -
-# File actioncable/lib/action_cable/helpers/action_cable_helper.rb, line 33
-def action_cable_meta_tag
- tag "meta", name: "action-cable-url", content: (
- ActionCable.server.config.url ||
- ActionCable.server.config.mount_path ||
- raise("No Action Cable URL configured -- please configure this at config.action_cable.url")
- )
-end
- # File actioncable/lib/action_cable/remote_connections.rb, line 25
+ def initialize(server)
+ @server = server
+ end
- - Source: - -
-# File actioncable/lib/action_cable/remote_connections.rb, line 25
-def initialize(server)
- @server = server
-end
- # File actioncable/lib/action_cable/remote_connections.rb, line 29
+ def where(identifier)
+ RemoteConnection.new(server, identifier)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/remote_connections.rb, line 29
-def where(identifier)
- RemoteConnection.new(server, identifier)
-end
- # File actioncable/lib/action_cable/remote_connections.rb, line 41
+ def initialize(server, ids)
+ @server = server
+ set_identifier_instance_vars(ids)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/remote_connections.rb, line 41
-def initialize(server, ids)
- @server = server
- set_identifier_instance_vars(ids)
-end
- # File actioncable/lib/action_cable/remote_connections.rb, line 47
+ def disconnect
+ server.broadcast internal_channel, type: "disconnect"
+ end
- - Source: - -
-# File actioncable/lib/action_cable/remote_connections.rb, line 47
-def disconnect
- server.broadcast internal_channel, type: "disconnect"
-end
- # File actioncable/lib/action_cable/server/base.rb, line 17
+ def self.logger; config.logger; end
- - Source: - -
-# File actioncable/lib/action_cable/server/base.rb, line 17
-def self.logger; config.logger; end
- # File actioncable/lib/action_cable/server/base.rb, line 22
+ def initialize
+ @mutex = Monitor.new
+ @remote_connections = @event_loop = @worker_pool = @pubsub = nil
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/base.rb, line 22
-def initialize
- @mutex = Monitor.new
- @remote_connections = @event_loop = @worker_pool = @pubsub = nil
-end
- # File actioncable/lib/action_cable/server/base.rb, line 28
+ def call(env)
+ setup_heartbeat_timer
+ config.connection_class.call.new(self, env).process
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/base.rb, line 28
-def call(env)
- setup_heartbeat_timer
- config.connection_class.call.new(self, env).process
-end
- # File actioncable/lib/action_cable/server/base.rb, line 82
+ def connection_identifiers
+ config.connection_class.call.identifiers
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/base.rb, line 82
-def connection_identifiers
- config.connection_class.call.identifiers
-end
- # File actioncable/lib/action_cable/server/base.rb, line 34
+ def disconnect(identifiers)
+ remote_connections.where(identifiers).disconnect
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/base.rb, line 34
-def disconnect(identifiers)
- remote_connections.where(identifiers).disconnect
-end
- # File actioncable/lib/action_cable/server/base.rb, line 57
+ def event_loop
+ @event_loop || @mutex.synchronize { @event_loop ||= ActionCable::Connection::StreamEventLoop.new }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/base.rb, line 57
-def event_loop
- @event_loop || @mutex.synchronize { @event_loop ||= ActionCable::Connection::StreamEventLoop.new }
-end
- # File actioncable/lib/action_cable/server/base.rb, line 77
+ def pubsub
+ @pubsub || @mutex.synchronize { @pubsub ||= config.pubsub_adapter.new(self) }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/base.rb, line 77
-def pubsub
- @pubsub || @mutex.synchronize { @pubsub ||= config.pubsub_adapter.new(self) }
-end
- # File actioncable/lib/action_cable/server/base.rb, line 53
+ def remote_connections
+ @remote_connections || @mutex.synchronize { @remote_connections ||= RemoteConnections.new(self) }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/base.rb, line 53
-def remote_connections
- @remote_connections || @mutex.synchronize { @remote_connections ||= RemoteConnections.new(self) }
-end
- # File actioncable/lib/action_cable/server/base.rb, line 38
+ def restart
+ connections.each(&:close)
+
+ @mutex.synchronize do
+ # Shutdown the worker pool
+ @worker_pool.halt if @worker_pool
+ @worker_pool = nil
+
+ # Shutdown the pub/sub adapter
+ @pubsub.shutdown if @pubsub
+ @pubsub = nil
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/base.rb, line 38
-def restart
- connections.each(&:close)
-
- @mutex.synchronize do
- # Shutdown the worker pool
- @worker_pool.halt if @worker_pool
- @worker_pool = nil
-
- # Shutdown the pub/sub adapter
- @pubsub.shutdown if @pubsub
- @pubsub = nil
- end
-end
- # File actioncable/lib/action_cable/server/base.rb, line 72
+ def worker_pool
+ @worker_pool || @mutex.synchronize { @worker_pool ||= ActionCable::Server::Worker.new(max_size: config.worker_pool_size) }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/base.rb, line 72
-def worker_pool
- @worker_pool || @mutex.synchronize { @worker_pool ||= ActionCable::Server::Worker.new(max_size: config.worker_pool_size) }
-end
- # File actioncable/lib/action_cable/server/broadcasting.rb, line 24
+ def broadcast(broadcasting, message, coder: ActiveSupport::JSON)
+ broadcaster_for(broadcasting, coder: coder).broadcast(message)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/broadcasting.rb, line 24
-def broadcast(broadcasting, message, coder: ActiveSupport::JSON)
- broadcaster_for(broadcasting, coder: coder).broadcast(message)
-end
- # File actioncable/lib/action_cable/server/broadcasting.rb, line 30
+ def broadcaster_for(broadcasting, coder: ActiveSupport::JSON)
+ Broadcaster.new(self, String(broadcasting), coder: coder)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/broadcasting.rb, line 30
-def broadcaster_for(broadcasting, coder: ActiveSupport::JSON)
- Broadcaster.new(self, String(broadcasting), coder: coder)
-end
- # File actioncable/lib/action_cable/server/broadcasting.rb, line 38
+ def initialize(server, broadcasting, coder:)
+ @server, @broadcasting, @coder = server, broadcasting, coder
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/broadcasting.rb, line 38
-def initialize(server, broadcasting, coder:)
- @server, @broadcasting, @coder = server, broadcasting, coder
-end
- # File actioncable/lib/action_cable/server/broadcasting.rb, line 42
+ def broadcast(message)
+ server.logger.debug "[ActionCable] Broadcasting to #{broadcasting}: #{message.inspect}"
+
+ payload = { broadcasting: broadcasting, message: message, coder: coder }
+ ActiveSupport::Notifications.instrument("broadcast.action_cable", payload) do
+ encoded = coder ? coder.encode(message) : message
+ server.pubsub.broadcast broadcasting, encoded
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/broadcasting.rb, line 42
-def broadcast(message)
- server.logger.debug "[ActionCable] Broadcasting to #{broadcasting}: #{message.inspect}"
-
- payload = { broadcasting: broadcasting, message: message, coder: coder }
- ActiveSupport::Notifications.instrument("broadcast.action_cable", payload) do
- encoded = coder ? coder.encode(message) : message
- server.pubsub.broadcast broadcasting, encoded
- end
-end
- - Source: - -
-# File actioncable/lib/action_cable/server/configuration.rb, line 13
-def initialize
- @log_tags = []
+
+
+
+ 📝 Source code
+
- @connection_class = -> { ActionCable::Connection::Base }
- @worker_pool_size = 4
+ # File actioncable/lib/action_cable/server/configuration.rb, line 13
+ def initialize
+ @log_tags = []
- @disable_request_forgery_protection = false
- @allow_same_origin_as_host = true
-end
-
- Source: - -
-# File actioncable/lib/action_cable/server/configuration.rb, line 26
-def pubsub_adapter
- adapter = (cable.fetch("adapter") { "redis" })
+
+
+
+ 📝 Source code
+
- # Require the adapter itself and give useful feedback about
- # 1. Missing adapter gems and
- # 2. Adapter gems' missing dependencies.
- path_to_adapter = "action_cable/subscription_adapter/#{adapter}"
- begin
- require path_to_adapter
- rescue LoadError => e
- # We couldn't require the adapter itself. Raise an exception that
- # points out config typos and missing gems.
- if e.path == path_to_adapter
- # We can assume that a non-builtin adapter was specified, so it's
- # either misspelled or missing from Gemfile.
- raise e.class, "Could not load the '#{adapter}' Action Cable pubsub adapter. Ensure that the adapter is spelled correctly in config/cable.yml and that you've added the necessary adapter gem to your Gemfile.", e.backtrace
+ # File actioncable/lib/action_cable/server/configuration.rb, line 26
+ def pubsub_adapter
+ adapter = (cable.fetch("adapter") { "redis" })
- # Bubbled up from the adapter require. Prefix the exception message
- # with some guidance about how to address it and reraise.
- else
- raise e.class, "Error loading the '#{adapter}' Action Cable pubsub adapter. Missing a gem it depends on? #{e.message}", e.backtrace
- end
- end
+ # Require the adapter itself and give useful feedback about
+ # 1. Missing adapter gems and
+ # 2. Adapter gems' missing dependencies.
+ path_to_adapter = "action_cable/subscription_adapter/#{adapter}"
+ begin
+ require path_to_adapter
+ rescue LoadError => e
+ # We couldn't require the adapter itself. Raise an exception that
+ # points out config typos and missing gems.
+ if e.path == path_to_adapter
+ # We can assume that a non-builtin adapter was specified, so it's
+ # either misspelled or missing from Gemfile.
+ raise e.class, "Could not load the '#{adapter}' Action Cable pubsub adapter. Ensure that the adapter is spelled correctly in config/cable.yml and that you've added the necessary adapter gem to your Gemfile.", e.backtrace
- adapter = adapter.camelize
- adapter = "PostgreSQL" if adapter == "Postgresql"
- "ActionCable::SubscriptionAdapter::#{adapter}".constantize
-end
-
# File actioncable/lib/action_cable/server/worker/active_record_connection_management.rb, line 15
+ def with_database_connections
+ connection.logger.tag(ActiveRecord::Base.logger) { yield }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/server/worker/active_record_connection_management.rb, line 15
-def with_database_connections
- connection.logger.tag(ActiveRecord::Base.logger) { yield }
-end
- # File actioncable/lib/action_cable/subscription_adapter/async.rb, line 14
+ def initialize(event_loop)
+ @event_loop = event_loop
+ super()
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/async.rb, line 14
-def initialize(event_loop)
- @event_loop = event_loop
- super()
-end
- # File actioncable/lib/action_cable/subscription_adapter/async.rb, line 19
+ def add_subscriber(*)
+ @event_loop.post { super }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/async.rb, line 19
-def add_subscriber(*)
- @event_loop.post { super }
-end
- # File actioncable/lib/action_cable/subscription_adapter/async.rb, line 23
+ def invoke_callback(*)
+ @event_loop.post { super }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/async.rb, line 23
-def invoke_callback(*)
- @event_loop.post { super }
-end
- # File actioncable/lib/action_cable/subscription_adapter/base.rb, line 8
+ def initialize(server)
+ @server = server
+ @logger = @server.logger
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/base.rb, line 8
-def initialize(server)
- @server = server
- @logger = @server.logger
-end
- # File actioncable/lib/action_cable/subscription_adapter/base.rb, line 13
+ def broadcast(channel, payload)
+ raise NotImplementedError
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/base.rb, line 13
-def broadcast(channel, payload)
- raise NotImplementedError
-end
- # File actioncable/lib/action_cable/subscription_adapter/base.rb, line 25
+ def shutdown
+ raise NotImplementedError
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/base.rb, line 25
-def shutdown
- raise NotImplementedError
-end
- # File actioncable/lib/action_cable/subscription_adapter/base.rb, line 17
+ def subscribe(channel, message_callback, success_callback = nil)
+ raise NotImplementedError
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/base.rb, line 17
-def subscribe(channel, message_callback, success_callback = nil)
- raise NotImplementedError
-end
- # File actioncable/lib/action_cable/subscription_adapter/base.rb, line 21
+ def unsubscribe(channel, message_callback)
+ raise NotImplementedError
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/base.rb, line 21
-def unsubscribe(channel, message_callback)
- raise NotImplementedError
-end
- # File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 56
+ def initialize(adapter, event_loop)
+ super()
+
+ @adapter = adapter
+ @event_loop = event_loop
+ @queue = Queue.new
+
+ @thread = Thread.new do
+ Thread.current.abort_on_exception = true
+ listen
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 56
-def initialize(adapter, event_loop)
- super()
-
- @adapter = adapter
- @event_loop = event_loop
- @queue = Queue.new
-
- @thread = Thread.new do
- Thread.current.abort_on_exception = true
- listen
- end
-end
- # File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 100
+ def add_channel(channel, on_success)
+ @queue.push([:listen, channel, on_success])
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 100
-def add_channel(channel, on_success)
- @queue.push([:listen, channel, on_success])
-end
- # File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 108
+ def invoke_callback(*)
+ @event_loop.post { super }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 108
-def invoke_callback(*)
- @event_loop.post { super }
-end
- # File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 69
+ def listen
+ @adapter.with_connection do |pg_conn|
+ catch :shutdown do
+ loop do
+ until @queue.empty?
+ action, channel, callback = @queue.pop(true)
+
+ case action
+ when :listen
+ pg_conn.exec("LISTEN #{pg_conn.escape_identifier channel}")
+ @event_loop.post(&callback) if callback
+ when :unlisten
+ pg_conn.exec("UNLISTEN #{pg_conn.escape_identifier channel}")
+ when :shutdown
+ throw :shutdown
+ end
+ end
+
+ pg_conn.wait_for_notify(1) do |chan, pid, message|
+ broadcast(chan, message)
+ end
+ end
+ end
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 69
-def listen
- @adapter.with_connection do |pg_conn|
- catch :shutdown do
- loop do
- until @queue.empty?
- action, channel, callback = @queue.pop(true)
-
- case action
- when :listen
- pg_conn.exec("LISTEN #{pg_conn.escape_identifier channel}")
- @event_loop.post(&callback) if callback
- when :unlisten
- pg_conn.exec("UNLISTEN #{pg_conn.escape_identifier channel}")
- when :shutdown
- throw :shutdown
- end
- end
-
- pg_conn.wait_for_notify(1) do |chan, pid, message|
- broadcast(chan, message)
- end
- end
- end
- end
-end
- # File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 104
+ def remove_channel(channel)
+ @queue.push([:unlisten, channel])
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 104
-def remove_channel(channel)
- @queue.push([:unlisten, channel])
-end
- # File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 95
+ def shutdown
+ @queue.push([:shutdown])
+ Thread.pass while @thread.alive?
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/postgresql.rb, line 95
-def shutdown
- @queue.push([:shutdown])
- Thread.pass while @thread.alive?
-end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 61
-def initialize(adapter, event_loop)
- super()
+
+
+
+ 📝 Source code
+
- @adapter = adapter
- @event_loop = event_loop
+ # File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 61
+ def initialize(adapter, event_loop)
+ super()
- @subscribe_callbacks = Hash.new { |h, k| h[k] = [] }
- @subscription_lock = Mutex.new
+ @adapter = adapter
+ @event_loop = event_loop
- @raw_client = nil
+ @subscribe_callbacks = Hash.new { |h, k| h[k] = [] }
+ @subscription_lock = Mutex.new
- @when_connected = []
+ @raw_client = nil
- @thread = nil
-end
-
# File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 128
+ def add_channel(channel, on_success)
+ @subscription_lock.synchronize do
+ ensure_listener_running
+ @subscribe_callbacks[channel] << on_success
+ when_connected { send_command("subscribe", channel) }
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 128
-def add_channel(channel, on_success)
- @subscription_lock.synchronize do
- ensure_listener_running
- @subscribe_callbacks[channel] << on_success
- when_connected { send_command("subscribe", channel) }
- end
-end
- # File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 142
+ def invoke_callback(*)
+ @event_loop.post { super }
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 142
-def invoke_callback(*)
- @event_loop.post { super }
-end
- # File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 77
+ def listen(conn)
+ conn.without_reconnect do
+ original_client = conn.respond_to?(:_client) ? conn._client : conn.client
+
+ conn.subscribe("_action_cable_internal") do |on|
+ on.subscribe do |chan, count|
+ @subscription_lock.synchronize do
+ if count == 1
+ @raw_client = original_client
+
+ until @when_connected.empty?
+ @when_connected.shift.call
+ end
+ end
+
+ if callbacks = @subscribe_callbacks[chan]
+ next_callback = callbacks.shift
+ @event_loop.post(&next_callback) if next_callback
+ @subscribe_callbacks.delete(chan) if callbacks.empty?
+ end
+ end
+ end
+
+ on.message do |chan, message|
+ broadcast(chan, message)
+ end
+
+ on.unsubscribe do |chan, count|
+ if count == 0
+ @subscription_lock.synchronize do
+ @raw_client = nil
+ end
+ end
+ end
+ end
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 77
-def listen(conn)
- conn.without_reconnect do
- original_client = conn.respond_to?(:_client) ? conn._client : conn.client
-
- conn.subscribe("_action_cable_internal") do |on|
- on.subscribe do |chan, count|
- @subscription_lock.synchronize do
- if count == 1
- @raw_client = original_client
-
- until @when_connected.empty?
- @when_connected.shift.call
- end
- end
-
- if callbacks = @subscribe_callbacks[chan]
- next_callback = callbacks.shift
- @event_loop.post(&next_callback) if next_callback
- @subscribe_callbacks.delete(chan) if callbacks.empty?
- end
- end
- end
-
- on.message do |chan, message|
- broadcast(chan, message)
- end
-
- on.unsubscribe do |chan, count|
- if count == 0
- @subscription_lock.synchronize do
- @raw_client = nil
- end
- end
- end
- end
- end
-end
- # File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 136
+ def remove_channel(channel)
+ @subscription_lock.synchronize do
+ when_connected { send_command("unsubscribe", channel) }
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 136
-def remove_channel(channel)
- @subscription_lock.synchronize do
- when_connected { send_command("unsubscribe", channel) }
- end
-end
- # File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 115
+ def shutdown
+ @subscription_lock.synchronize do
+ return if @thread.nil?
+
+ when_connected do
+ send_command("unsubscribe")
+ @raw_client = nil
+ end
+ end
+
+ Thread.pass while @thread.alive?
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/redis.rb, line 115
-def shutdown
- @subscription_lock.synchronize do
- return if @thread.nil?
-
- when_connected do
- send_command("unsubscribe")
- @raw_client = nil
- end
- end
-
- Thread.pass while @thread.alive?
-end
- # File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 6
+ def initialize
+ @subscribers = Hash.new { |h, k| h[k] = [] }
+ @sync = Mutex.new
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 6
-def initialize
- @subscribers = Hash.new { |h, k| h[k] = [] }
- @sync = Mutex.new
-end
- # File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 47
+ def add_channel(channel, on_success)
+ on_success.call if on_success
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 47
-def add_channel(channel, on_success)
- on_success.call if on_success
-end
- # File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 11
+ def add_subscriber(channel, subscriber, on_success)
+ @sync.synchronize do
+ new_channel = !@subscribers.key?(channel)
+
+ @subscribers[channel] << subscriber
+
+ if new_channel
+ add_channel channel, on_success
+ elsif on_success
+ on_success.call
+ end
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 11
-def add_subscriber(channel, subscriber, on_success)
- @sync.synchronize do
- new_channel = !@subscribers.key?(channel)
-
- @subscribers[channel] << subscriber
-
- if new_channel
- add_channel channel, on_success
- elsif on_success
- on_success.call
- end
- end
-end
- # File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 36
+ def broadcast(channel, message)
+ list = @sync.synchronize do
+ return if !@subscribers.key?(channel)
+ @subscribers[channel].dup
+ end
+
+ list.each do |subscriber|
+ invoke_callback(subscriber, message)
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 36
-def broadcast(channel, message)
- list = @sync.synchronize do
- return if !@subscribers.key?(channel)
- @subscribers[channel].dup
- end
-
- list.each do |subscriber|
- invoke_callback(subscriber, message)
- end
-end
- # File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 54
+ def invoke_callback(callback, message)
+ callback.call message
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 54
-def invoke_callback(callback, message)
- callback.call message
-end
- # File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 51
+ def remove_channel(channel)
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 51
-def remove_channel(channel)
-end
- # File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 25
+ def remove_subscriber(channel, subscriber)
+ @sync.synchronize do
+ @subscribers[channel].delete(subscriber)
+
+ if @subscribers[channel].empty?
+ @subscribers.delete channel
+ remove_channel channel
+ end
+ end
+ end
- - Source: - -
-# File actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb, line 25
-def remove_subscriber(channel, subscriber)
- @sync.synchronize do
- @subscribers[channel].delete(subscriber)
-
- if @subscribers[channel].empty?
- @subscribers.delete channel
- remove_channel channel
- end
- end
-end
- # File actionpack/lib/action_controller/metal/renderers.rb, line 7
+ def self.add_renderer(key, &block)
+ Renderers.add(key, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/renderers.rb, line 7
-def self.add_renderer(key, &block)
- Renderers.add(key, &block)
-end
- # File actionpack/lib/action_controller/metal/renderers.rb, line 12
+ def self.remove_renderer(key)
+ Renderers.remove(key)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/renderers.rb, line 12
-def self.remove_renderer(key)
- Renderers.remove(key)
-end
- # File actionpack/lib/action_controller/api.rb, line 104
+ def self.without_modules(*modules)
+ modules = modules.map do |m|
+ m.is_a?(Symbol) ? ActionController.const_get(m) : m
+ end
+
+ MODULES - modules
+ end
- - Source: - -
-# File actionpack/lib/action_controller/api.rb, line 104
-def self.without_modules(*modules)
- modules = modules.map do |m|
- m.is_a?(Symbol) ? ActionController.const_get(m) : m
- end
-
- MODULES - modules
-end
- # File actionpack/lib/action_controller/api/api_rendering.rb, line 11
+ def render_to_body(options = {})
+ _process_options(options)
+ super
+ end
- - Source: - -
-# File actionpack/lib/action_controller/api/api_rendering.rb, line 11
-def render_to_body(options = {})
- _process_options(options)
- super
-end
- # File actionpack/lib/action_controller/base.rb, line 267
+ def self.make_response!(request)
+ ActionDispatch::Response.create.tap do |res|
+ res.request = request
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/base.rb, line 267
-def self.make_response!(request)
- ActionDispatch::Response.create.tap do |res|
- res.request = request
- end
-end
- # File actionpack/lib/action_controller/base.rb, line 197
+ def self.without_modules(*modules)
+ modules = modules.map do |m|
+ m.is_a?(Symbol) ? ActionController.const_get(m) : m
+ end
+
+ MODULES - modules
+ end
- - Source: - -
-# File actionpack/lib/action_controller/base.rb, line 197
-def self.without_modules(*modules)
- modules = modules.map do |m|
- m.is_a?(Symbol) ? ActionController.const_get(m) : m
- end
-
- MODULES - modules
-end
- - Source: - -
-# File actionpack/lib/action_controller/base.rb, line 174
-
- - Source: - -
-# File actionpack/lib/action_controller/base.rb, line 180
-
- # File actionpack/lib/action_controller/metal/conditional_get.rb, line 234
+ def expires_in(seconds, options = {})
+ response.cache_control.merge!(
+ max_age: seconds,
+ public: options.delete(:public),
+ must_revalidate: options.delete(:must_revalidate)
+ )
+ options.delete(:private)
+
+ response.cache_control[:extras] = options.map { |k, v| "#{k}=#{v}" }
+ response.date = Time.now unless response.date?
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/conditional_get.rb, line 234
-def expires_in(seconds, options = {})
- response.cache_control.merge!(
- max_age: seconds,
- public: options.delete(:public),
- must_revalidate: options.delete(:must_revalidate)
- )
- options.delete(:private)
-
- response.cache_control[:extras] = options.map { |k, v| "#{k}=#{v}" }
- response.date = Time.now unless response.date?
-end
- # File actionpack/lib/action_controller/metal/conditional_get.rb, line 249
+ def expires_now
+ response.cache_control.replace(no_cache: true)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/conditional_get.rb, line 249
-def expires_now
- response.cache_control.replace(no_cache: true)
-end
- # File actionpack/lib/action_controller/metal/conditional_get.rb, line 105
+ def fresh_when(object = nil, etag: nil, weak_etag: nil, strong_etag: nil, last_modified: nil, public: false, template: nil)
+ weak_etag ||= etag || object unless strong_etag
+ last_modified ||= object.try(:updated_at) || object.try(:maximum, :updated_at)
+
+ if strong_etag
+ response.strong_etag = combine_etags strong_etag,
+ last_modified: last_modified, public: public, template: template
+ elsif weak_etag || template
+ response.weak_etag = combine_etags weak_etag,
+ last_modified: last_modified, public: public, template: template
+ end
+
+ response.last_modified = last_modified if last_modified
+ response.cache_control[:public] = true if public
+
+ head :not_modified if request.fresh?(response)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/conditional_get.rb, line 105
-def fresh_when(object = nil, etag: nil, weak_etag: nil, strong_etag: nil, last_modified: nil, public: false, template: nil)
- weak_etag ||= etag || object unless strong_etag
- last_modified ||= object.try(:updated_at) || object.try(:maximum, :updated_at)
-
- if strong_etag
- response.strong_etag = combine_etags strong_etag,
- last_modified: last_modified, public: public, template: template
- elsif weak_etag || template
- response.weak_etag = combine_etags weak_etag,
- last_modified: last_modified, public: public, template: template
- end
-
- response.last_modified = last_modified if last_modified
- response.cache_control[:public] = true if public
-
- head :not_modified if request.fresh?(response)
-end
- # File actionpack/lib/action_controller/metal/conditional_get.rb, line 261
+ def http_cache_forever(public: false)
+ expires_in 100.years, public: public
+
+ yield if stale?(etag: request.fullpath,
+ last_modified: Time.new(2011, 1, 1).utc,
+ public: public)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/conditional_get.rb, line 261
-def http_cache_forever(public: false)
- expires_in 100.years, public: public
-
- yield if stale?(etag: request.fullpath,
- last_modified: Time.new(2011, 1, 1).utc,
- public: public)
-end
- # File actionpack/lib/action_controller/metal/conditional_get.rb, line 218
+ def stale?(object = nil, **freshness_kwargs)
+ fresh_when(object, **freshness_kwargs)
+ !request.fresh?(response)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/conditional_get.rb, line 218
-def stale?(object = nil, **freshness_kwargs)
- fresh_when(object, **freshness_kwargs)
- !request.fresh?(response)
-end
- # File actionpack/lib/action_controller/metal/conditional_get.rb, line 30
+ def etag(&etagger)
+ self.etaggers += [etagger]
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/conditional_get.rb, line 30
-def etag(&etagger)
- self.etaggers += [etagger]
-end
- # File actionpack/lib/action_controller/metal/content_security_policy.rb, line 17
+ def content_security_policy(enabled = true, **options, &block)
+ before_action(options) do
+ if block_given?
+ policy = current_content_security_policy
+ yield policy
+ request.content_security_policy = policy
+ end
+
+ unless enabled
+ request.content_security_policy = nil
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/content_security_policy.rb, line 17
-def content_security_policy(enabled = true, **options, &block)
- before_action(options) do
- if block_given?
- policy = current_content_security_policy
- yield policy
- request.content_security_policy = policy
- end
-
- unless enabled
- request.content_security_policy = nil
- end
- end
-end
- # File actionpack/lib/action_controller/metal/content_security_policy.rb, line 31
+ def content_security_policy_report_only(report_only = true, **options)
+ before_action(options) do
+ request.content_security_policy_report_only = report_only
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/content_security_policy.rb, line 31
-def content_security_policy_report_only(report_only = true, **options)
- before_action(options) do
- request.content_security_policy_report_only = report_only
- end
-end
- # File actionpack/lib/action_controller/metal/data_streaming.rb, line 108
+ def send_data(data, options = {}) #:doc:
+ send_file_headers! options
+ render options.slice(:status, :content_type).merge(body: data)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/data_streaming.rb, line 108
-def send_data(data, options = {}) #:doc:
- send_file_headers! options
- render options.slice(:status, :content_type).merge(body: data)
-end
- # File actionpack/lib/action_controller/metal/data_streaming.rb, line 68
+ def send_file(path, options = {}) #:doc:
+ raise MissingFile, "Cannot read file #{path}" unless File.file?(path) && File.readable?(path)
+
+ options[:filename] ||= File.basename(path) unless options[:url_based_filename]
+ send_file_headers! options
+
+ self.status = options[:status] || 200
+ self.content_type = options[:content_type] if options.key?(:content_type)
+ response.send_file path
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/data_streaming.rb, line 68
-def send_file(path, options = {}) #:doc:
- raise MissingFile, "Cannot read file #{path}" unless File.file?(path) && File.readable?(path)
-
- options[:filename] ||= File.basename(path) unless options[:url_based_filename]
- send_file_headers! options
-
- self.status = options[:status] || 200
- self.content_type = options[:content_type] if options.key?(:content_type)
- response.send_file path
-end
- # File actionpack/lib/action_controller/metal/flash.rb, line 47
+ def redirect_to(options = {}, response_status_and_flash = {}) #:doc:
+ self.class._flash_types.each do |flash_type|
+ if type = response_status_and_flash.delete(flash_type)
+ flash[flash_type] = type
+ end
+ end
+
+ if other_flashes = response_status_and_flash.delete(:flash)
+ flash.update(other_flashes)
+ end
+
+ super(options, response_status_and_flash)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/flash.rb, line 47
-def redirect_to(options = {}, response_status_and_flash = {}) #:doc:
- self.class._flash_types.each do |flash_type|
- if type = response_status_and_flash.delete(flash_type)
- flash[flash_type] = type
- end
- end
-
- if other_flashes = response_status_and_flash.delete(:flash)
- flash.update(other_flashes)
- end
-
- super(options, response_status_and_flash)
-end
- # File actionpack/lib/action_controller/metal/flash.rb, line 32
+ def add_flash_types(*types)
+ types.each do |type|
+ next if _flash_types.include?(type)
+
+ define_method(type) do
+ request.flash[type]
+ end
+ helper_method type
+
+ self._flash_types += [type]
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/flash.rb, line 32
-def add_flash_types(*types)
- types.each do |type|
- next if _flash_types.include?(type)
-
- define_method(type) do
- request.flash[type]
- end
- helper_method type
-
- self._flash_types += [type]
- end
-end
- # File actionpack/lib/action_controller/metal/force_ssl.rb, line 78
+ def force_ssl_redirect(host_or_options = nil)
+ unless request.ssl?
+ options = {
+ protocol: "https://",
+ host: request.host,
+ path: request.fullpath,
+ status: :moved_permanently
+ }
+
+ if host_or_options.is_a?(Hash)
+ options.merge!(host_or_options)
+ elsif host_or_options
+ options[:host] = host_or_options
+ end
+
+ secure_url = ActionDispatch::Http::URL.url_for(options.slice(*URL_OPTIONS))
+ flash.keep if respond_to?(:flash) && request.respond_to?(:flash)
+ redirect_to secure_url, options.slice(*REDIRECT_OPTIONS)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/force_ssl.rb, line 78
-def force_ssl_redirect(host_or_options = nil)
- unless request.ssl?
- options = {
- protocol: "https://",
- host: request.host,
- path: request.fullpath,
- status: :moved_permanently
- }
-
- if host_or_options.is_a?(Hash)
- options.merge!(host_or_options)
- elsif host_or_options
- options[:host] = host_or_options
- end
-
- secure_url = ActionDispatch::Http::URL.url_for(options.slice(*URL_OPTIONS))
- flash.keep if respond_to?(:flash) && request.respond_to?(:flash)
- redirect_to secure_url, options.slice(*REDIRECT_OPTIONS)
- end
-end
- # File actionpack/lib/action_controller/metal/force_ssl.rb, line 64
+ def force_ssl(options = {})
+ action_options = options.slice(*ACTION_OPTIONS)
+ redirect_options = options.except(*ACTION_OPTIONS)
+ before_action(action_options) do
+ force_ssl_redirect(redirect_options)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/force_ssl.rb, line 64
-def force_ssl(options = {})
- action_options = options.slice(*ACTION_OPTIONS)
- redirect_options = options.except(*ACTION_OPTIONS)
- before_action(action_options) do
- force_ssl_redirect(redirect_options)
- end
-end
- # File actionpack/lib/action_controller/form_builder.rb, line 46
+ def default_form_builder
+ self.class._default_form_builder
+ end
- - Source: - -
-# File actionpack/lib/action_controller/form_builder.rb, line 46
-def default_form_builder
- self.class._default_form_builder
-end
- # File actionpack/lib/action_controller/form_builder.rb, line 40
+ def default_form_builder(builder)
+ self._default_form_builder = builder
+ end
- - Source: - -
-# File actionpack/lib/action_controller/form_builder.rb, line 40
-def default_form_builder(builder)
- self._default_form_builder = builder
-end
- # File actionpack/lib/action_controller/metal/head.rb, line 21
+ def head(status, options = {})
+ if status.is_a?(Hash)
+ raise ArgumentError, "#{status.inspect} is not a valid value for `status`."
+ end
+
+ status ||= :ok
+
+ location = options.delete(:location)
+ content_type = options.delete(:content_type)
+
+ options.each do |key, value|
+ headers[key.to_s.dasherize.split("-").each { |v| v[0] = v[0].chr.upcase }.join("-")] = value.to_s
+ end
+
+ self.status = status
+ self.location = url_for(location) if location
+
+ self.response_body = ""
+
+ if include_content?(response_code)
+ self.content_type = content_type || (Mime[formats.first] if formats)
+ response.charset = false
+ end
+
+ true
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/head.rb, line 21
-def head(status, options = {})
- if status.is_a?(Hash)
- raise ArgumentError, "#{status.inspect} is not a valid value for `status`."
- end
-
- status ||= :ok
-
- location = options.delete(:location)
- content_type = options.delete(:content_type)
-
- options.each do |key, value|
- headers[key.to_s.dasherize.split("-").each { |v| v[0] = v[0].chr.upcase }.join("-")] = value.to_s
- end
-
- self.status = status
- self.location = url_for(location) if location
-
- self.response_body = ""
-
- if include_content?(response_code)
- self.content_type = content_type || (Mime[formats.first] if formats)
- response.charset = false
- end
-
- true
-end
- # File actionpack/lib/action_controller/metal/helpers.rb, line 119
+ def helpers
+ @_helper_proxy ||= view_context
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/helpers.rb, line 119
-def helpers
- @_helper_proxy ||= view_context
-end
- # File actionpack/lib/action_controller/metal/helpers.rb, line 101
+ def all_helpers_from_path(path)
+ helpers = Array(path).flat_map do |_path|
+ extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/
+ names = Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1'.freeze) }
+ names.sort!
+ end
+ helpers.uniq!
+ helpers
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/helpers.rb, line 101
-def all_helpers_from_path(path)
- helpers = Array(path).flat_map do |_path|
- extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/
- names = Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1'.freeze) }
- names.sort!
- end
- helpers.uniq!
- helpers
-end
- # File actionpack/lib/action_controller/metal/helpers.rb, line 76
+ def helpers
+ @helper_proxy ||= begin
+ proxy = ActionView::Base.new
+ proxy.config = config.inheritable_copy
+ proxy.extend(_helpers)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/helpers.rb, line 76
-def helpers
- @helper_proxy ||= begin
- proxy = ActionView::Base.new
- proxy.config = config.inheritable_copy
- proxy.extend(_helpers)
- end
-end
- # File actionpack/lib/action_controller/metal/helpers.rb, line 92
+ def modules_for_helpers(args)
+ args += all_application_helpers if args.delete(:all)
+ super(args)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/helpers.rb, line 92
-def modules_for_helpers(args)
- args += all_application_helpers if args.delete(:all)
- super(args)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 119
+ def auth_param(request)
+ request.authorization.to_s.split(" ", 2).second
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 119
-def auth_param(request)
- request.authorization.to_s.split(" ", 2).second
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 115
+ def auth_scheme(request)
+ request.authorization.to_s.split(" ", 2).first
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 115
-def auth_scheme(request)
- request.authorization.to_s.split(" ", 2).first
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 97
+ def authenticate(request, &login_procedure)
+ if has_basic_credentials?(request)
+ login_procedure.call(*user_name_and_password(request))
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 97
-def authenticate(request, &login_procedure)
- if has_basic_credentials?(request)
- login_procedure.call(*user_name_and_password(request))
- end
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 127
+ def authentication_request(controller, realm, message)
+ message ||= "HTTP Basic: Access denied.\n"
+ controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.tr('"'.freeze, "".freeze)}")
+ controller.status = 401
+ controller.response_body = message
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 127
-def authentication_request(controller, realm, message)
- message ||= "HTTP Basic: Access denied.\n"
- controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.tr('"'.freeze, "".freeze)}")
- controller.status = 401
- controller.response_body = message
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 111
+ def decode_credentials(request)
+ ::Base64.decode64(auth_param(request) || "")
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 111
-def decode_credentials(request)
- ::Base64.decode64(auth_param(request) || "")
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 123
+ def encode_credentials(user_name, password)
+ "Basic #{::Base64.strict_encode64("#{user_name}:#{password}")}"
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 123
-def encode_credentials(user_name, password)
- "Basic #{::Base64.strict_encode64("#{user_name}:#{password}")}"
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 103
+ def has_basic_credentials?(request)
+ request.authorization.present? && (auth_scheme(request).downcase == "basic")
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 103
-def has_basic_credentials?(request)
- request.authorization.present? && (auth_scheme(request).downcase == "basic")
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 107
+ def user_name_and_password(request)
+ decode_credentials(request).split(":", 2)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 107
-def user_name_and_password(request)
- decode_credentials(request).split(":", 2)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 84
+ def authenticate_or_request_with_http_basic(realm = "Application", message = nil, &login_procedure)
+ authenticate_with_http_basic(&login_procedure) || request_http_basic_authentication(realm, message)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 84
-def authenticate_or_request_with_http_basic(realm = "Application", message = nil, &login_procedure)
- authenticate_with_http_basic(&login_procedure) || request_http_basic_authentication(realm, message)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 88
+ def authenticate_with_http_basic(&login_procedure)
+ HttpAuthentication::Basic.authenticate(request, &login_procedure)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 88
-def authenticate_with_http_basic(&login_procedure)
- HttpAuthentication::Basic.authenticate(request, &login_procedure)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 92
+ def request_http_basic_authentication(realm = "Application", message = nil)
+ HttpAuthentication::Basic.authentication_request(self, realm, message)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 92
-def request_http_basic_authentication(realm = "Application", message = nil)
- HttpAuthentication::Basic.authentication_request(self, realm, message)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 71
+ def http_basic_authenticate_with(options = {})
+ before_action(options.except(:name, :password, :realm)) do
+ authenticate_or_request_with_http_basic(options[:realm] || "Application") do |name, password|
+ # This comparison uses & so that it doesn't short circuit and
+ # uses `secure_compare` so that length information
+ # isn't leaked.
+ ActiveSupport::SecurityUtils.secure_compare(name, options[:name]) &
+ ActiveSupport::SecurityUtils.secure_compare(password, options[:password])
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 71
-def http_basic_authenticate_with(options = {})
- before_action(options.except(:name, :password, :realm)) do
- authenticate_or_request_with_http_basic(options[:realm] || "Application") do |name, password|
- # This comparison uses & so that it doesn't short circuit and
- # uses `secure_compare` so that length information
- # isn't leaked.
- ActiveSupport::SecurityUtils.secure_compare(name, options[:name]) &
- ActiveSupport::SecurityUtils.secure_compare(password, options[:password])
- end
- end
-end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 197
-def authenticate(request, realm, &password_procedure)
- request.authorization && validate_digest_response(request, realm, &password_procedure)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 197
+ def authenticate(request, realm, &password_procedure)
+ request.authorization && validate_digest_response(request, realm, &password_procedure)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 255
-def authentication_header(controller, realm)
- secret_key = secret_token(controller.request)
- nonce = self.nonce(secret_key)
- opaque = opaque(secret_key)
- controller.headers["WWW-Authenticate"] = %(Digest realm="#{realm}", qop="auth", algorithm=MD5, nonce="#{nonce}", opaque="#{opaque}")
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 255
+ def authentication_header(controller, realm)
+ secret_key = secret_token(controller.request)
+ nonce = self.nonce(secret_key)
+ opaque = opaque(secret_key)
+ controller.headers["WWW-Authenticate"] = %(Digest realm="#{realm}", qop="auth", algorithm=MD5, nonce="#{nonce}", opaque="#{opaque}")
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 262
-def authentication_request(controller, realm, message = nil)
- message ||= "HTTP Digest: Access denied.\n"
- authentication_header(controller, realm)
- controller.status = 401
- controller.response_body = message
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 262
+ def authentication_request(controller, realm, message = nil)
+ message ||= "HTTP Digest: Access denied.\n"
+ authentication_header(controller, realm)
+ controller.status = 401
+ controller.response_body = message
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 248
-def decode_credentials(header)
- ActiveSupport::HashWithIndifferentAccess[header.to_s.gsub(/^Digest\s+/, "").split(",").map do |pair|
- key, value = pair.split("=", 2)
- [key.strip, value.to_s.gsub(/^"|"$/, "").delete("'")]
- end]
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 248
+ def decode_credentials(header)
+ ActiveSupport::HashWithIndifferentAccess[header.to_s.gsub(/^Digest\s+/, "").split(",").map do |pair|
+ key, value = pair.split("=", 2)
+ [key.strip, value.to_s.gsub(/^"|"$/, "").delete("'")]
+ end]
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 244
-def decode_credentials_header(request)
- decode_credentials(request.authorization)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 244
+ def decode_credentials_header(request)
+ decode_credentials(request.authorization)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 239
-def encode_credentials(http_method, credentials, password, password_is_ha1)
- credentials[:response] = expected_response(http_method, credentials[:uri], credentials, password, password_is_ha1)
- "Digest " + credentials.sort_by { |x| x[0].to_s }.map { |v| "#{v[0]}='#{v[1]}'" }.join(", ")
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 239
+ def encode_credentials(http_method, credentials, password, password_is_ha1)
+ credentials[:response] = expected_response(http_method, credentials[:uri], credentials, password, password_is_ha1)
+ "Digest " + credentials.sort_by { |x| x[0].to_s }.map { |v| "#{v[0]}='#{v[1]}'" }.join(", ")
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 229
-def expected_response(http_method, uri, credentials, password, password_is_ha1 = true)
- ha1 = password_is_ha1 ? password : ha1(credentials, password)
- ha2 = ::Digest::MD5.hexdigest([http_method.to_s.upcase, uri].join(":"))
- ::Digest::MD5.hexdigest([ha1, credentials[:nonce], credentials[:nc], credentials[:cnonce], credentials[:qop], ha2].join(":"))
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 229
+ def expected_response(http_method, uri, credentials, password, password_is_ha1 = true)
+ ha1 = password_is_ha1 ? password : ha1(credentials, password)
+ ha2 = ::Digest::MD5.hexdigest([http_method.to_s.upcase, uri].join(":"))
+ ::Digest::MD5.hexdigest([ha1, credentials[:nonce], credentials[:nc], credentials[:cnonce], credentials[:qop], ha2].join(":"))
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 235
-def ha1(credentials, password)
- ::Digest::MD5.hexdigest([credentials[:username], credentials[:realm], password].join(":"))
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 235
+ def ha1(credentials, password)
+ ::Digest::MD5.hexdigest([credentials[:username], credentials[:realm], password].join(":"))
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 307
-def nonce(secret_key, time = Time.now)
- t = time.to_i
- hashed = [t, secret_key]
- digest = ::Digest::MD5.hexdigest(hashed.join(":"))
- ::Base64.strict_encode64("#{t}:#{digest}")
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 307
+ def nonce(secret_key, time = Time.now)
+ t = time.to_i
+ hashed = [t, secret_key]
+ digest = ::Digest::MD5.hexdigest(hashed.join(":"))
+ ::Base64.strict_encode64("#{t}:#{digest}")
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 326
-def opaque(secret_key)
- ::Digest::MD5.hexdigest(secret_key)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 326
+ def opaque(secret_key)
+ ::Digest::MD5.hexdigest(secret_key)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 269
-def secret_token(request)
- key_generator = request.key_generator
- http_auth_salt = request.http_auth_salt
- key_generator.generate_key(http_auth_salt)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 269
+ def secret_token(request)
+ key_generator = request.key_generator
+ http_auth_salt = request.http_auth_salt
+ key_generator.generate_key(http_auth_salt)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 204
-def validate_digest_response(request, realm, &password_procedure)
- secret_key = secret_token(request)
- credentials = decode_credentials_header(request)
- valid_nonce = validate_nonce(secret_key, request, credentials[:nonce])
-
- if valid_nonce && realm == credentials[:realm] && opaque(secret_key) == credentials[:opaque]
- password = password_procedure.call(credentials[:username])
- return false unless password
-
- method = request.get_header("rack.methodoverride.original_method") || request.get_header("REQUEST_METHOD")
- uri = credentials[:uri]
-
- [true, false].any? do |trailing_question_mark|
- [true, false].any? do |password_is_ha1|
- _uri = trailing_question_mark ? uri + "?" : uri
- expected = expected_response(method, _uri, credentials, password, password_is_ha1)
- expected == credentials[:response]
- end
- end
- end
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 204
+ def validate_digest_response(request, realm, &password_procedure)
+ secret_key = secret_token(request)
+ credentials = decode_credentials_header(request)
+ valid_nonce = validate_nonce(secret_key, request, credentials[:nonce])
+
+ if valid_nonce && realm == credentials[:realm] && opaque(secret_key) == credentials[:opaque]
+ password = password_procedure.call(credentials[:username])
+ return false unless password
+
+ method = request.get_header("rack.methodoverride.original_method") || request.get_header("REQUEST_METHOD")
+ uri = credentials[:uri]
+
+ [true, false].any? do |trailing_question_mark|
+ [true, false].any? do |password_is_ha1|
+ _uri = trailing_question_mark ? uri + "?" : uri
+ expected = expected_response(method, _uri, credentials, password, password_is_ha1)
+ expected == credentials[:response]
+ end
+ end
+ end
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 319
-def validate_nonce(secret_key, request, value, seconds_to_timeout = 5 * 60)
- return false if value.nil?
- t = ::Base64.decode64(value).split(":").first.to_i
- nonce(secret_key, t) == value && (t - Time.now.to_i).abs <= seconds_to_timeout
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 319
+ def validate_nonce(secret_key, request, value, seconds_to_timeout = 5 * 60)
+ return false if value.nil?
+ t = ::Base64.decode64(value).split(":").first.to_i
+ nonce(secret_key, t) == value && (t - Time.now.to_i).abs <= seconds_to_timeout
+ end
+
+ 🔎 See on GitHub
+
+ # File actionpack/lib/action_controller/metal/http_authentication.rb, line 181
+ def authenticate_or_request_with_http_digest(realm = "Application", message = nil, &password_procedure)
+ authenticate_with_http_digest(realm, &password_procedure) || request_http_digest_authentication(realm, message)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 181
-def authenticate_or_request_with_http_digest(realm = "Application", message = nil, &password_procedure)
- authenticate_with_http_digest(realm, &password_procedure) || request_http_digest_authentication(realm, message)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 186
+ def authenticate_with_http_digest(realm = "Application", &password_procedure)
+ HttpAuthentication::Digest.authenticate(request, realm, &password_procedure)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 186
-def authenticate_with_http_digest(realm = "Application", &password_procedure)
- HttpAuthentication::Digest.authenticate(request, realm, &password_procedure)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 191
+ def request_http_digest_authentication(realm = "Application", message = nil)
+ HttpAuthentication::Digest.authentication_request(self, realm, message)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 191
-def request_http_digest_authentication(realm = "Application", message = nil)
- HttpAuthentication::Digest.authentication_request(self, realm, message)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 440
+ def authenticate(controller, &login_procedure)
+ token, options = token_and_options(controller.request)
+ unless token.blank?
+ login_procedure.call(token, options)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 440
-def authenticate(controller, &login_procedure)
- token, options = token_and_options(controller.request)
- unless token.blank?
- login_procedure.call(token, options)
- end
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 512
+ def authentication_request(controller, realm, message = nil)
+ message ||= "HTTP Token: Access denied.\n"
+ controller.headers["WWW-Authenticate"] = %(Token realm="#{realm.tr('"'.freeze, "".freeze)}")
+ controller.__send__ :render, plain: message, status: :unauthorized
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 512
-def authentication_request(controller, realm, message = nil)
- message ||= "HTTP Token: Access denied.\n"
- controller.headers["WWW-Authenticate"] = %(Token realm="#{realm.tr('"'.freeze, "".freeze)}")
- controller.__send__ :render, plain: message, status: :unauthorized
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 499
+ def encode_credentials(token, options = {})
+ values = ["#{TOKEN_KEY}#{token.to_s.inspect}"] + options.map do |key, value|
+ "#{key}=#{value.to_s.inspect}"
+ end
+ "Token #{values * ", "}"
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 499
-def encode_credentials(token, options = {})
- values = ["#{TOKEN_KEY}#{token.to_s.inspect}"] + options.map do |key, value|
- "#{key}=#{value.to_s.inspect}"
- end
- "Token #{values * ", "}"
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 471
+ def params_array_from(raw_params)
+ raw_params.map { |param| param.split %r/=(.+)?/ }
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 471
-def params_array_from(raw_params)
- raw_params.map { |param| param.split %r/=(.+)?/ }
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 483
+ def raw_params(auth)
+ _raw_params = auth.sub(TOKEN_REGEX, "").split(/\s*#{AUTHN_PAIR_DELIMITERS}\s*/)
+
+ if !(_raw_params.first =~ %r{\A#{TOKEN_KEY}})
+ _raw_params[0] = "#{TOKEN_KEY}#{_raw_params.first}"
+ end
+
+ _raw_params
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 483
-def raw_params(auth)
- _raw_params = auth.sub(TOKEN_REGEX, "").split(/\s*#{AUTHN_PAIR_DELIMITERS}\s*/)
-
- if !(_raw_params.first =~ %r{\A#{TOKEN_KEY}})
- _raw_params[0] = "#{TOKEN_KEY}#{_raw_params.first}"
- end
-
- _raw_params
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 476
+ def rewrite_param_values(array_params)
+ array_params.each { |param| (param[1] || "".dup).gsub! %r/^"|"$/, "" }
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 476
-def rewrite_param_values(array_params)
- array_params.each { |param| (param[1] || "".dup).gsub! %r/^"|"$/, "" }
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 458
+ def token_and_options(request)
+ authorization_request = request.authorization.to_s
+ if authorization_request[TOKEN_REGEX]
+ params = token_params_from authorization_request
+ [params.shift[1], Hash[params].with_indifferent_access]
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 458
-def token_and_options(request)
- authorization_request = request.authorization.to_s
- if authorization_request[TOKEN_REGEX]
- params = token_params_from authorization_request
- [params.shift[1], Hash[params].with_indifferent_access]
- end
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 466
+ def token_params_from(auth)
+ rewrite_param_values params_array_from raw_params auth
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 466
-def token_params_from(auth)
- rewrite_param_values params_array_from raw_params auth
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 413
+ def authenticate_or_request_with_http_token(realm = "Application", message = nil, &login_procedure)
+ authenticate_with_http_token(&login_procedure) || request_http_token_authentication(realm, message)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 413
-def authenticate_or_request_with_http_token(realm = "Application", message = nil, &login_procedure)
- authenticate_with_http_token(&login_procedure) || request_http_token_authentication(realm, message)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 417
+ def authenticate_with_http_token(&login_procedure)
+ Token.authenticate(self, &login_procedure)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 417
-def authenticate_with_http_token(&login_procedure)
- Token.authenticate(self, &login_procedure)
-end
- # File actionpack/lib/action_controller/metal/http_authentication.rb, line 421
+ def request_http_token_authentication(realm = "Application", message = nil)
+ Token.authentication_request(self, realm, message)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/http_authentication.rb, line 421
-def request_http_token_authentication(realm = "Application", message = nil)
- Token.authentication_request(self, realm, message)
-end
- # File actionpack/lib/action_controller/metal/instrumentation.rb, line 19
+ def process_action(*args)
+ raw_payload = {
+ controller: self.class.name,
+ action: action_name,
+ params: request.filtered_parameters,
+ headers: request.headers,
+ format: request.format.ref,
+ method: request.request_method,
+ path: request.fullpath
+ }
+
+ ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload.dup)
+
+ ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload|
+ begin
+ result = super
+ payload[:status] = response.status
+ result
+ ensure
+ append_info_to_payload(payload)
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/instrumentation.rb, line 19
-def process_action(*args)
- raw_payload = {
- controller: self.class.name,
- action: action_name,
- params: request.filtered_parameters,
- headers: request.headers,
- format: request.format.ref,
- method: request.request_method,
- path: request.fullpath
- }
-
- ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload.dup)
-
- ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload|
- begin
- result = super
- payload[:status] = response.status
- result
- ensure
- append_info_to_payload(payload)
- end
- end
-end
- # File actionpack/lib/action_controller/metal/instrumentation.rb, line 64
+ def redirect_to(*args)
+ ActiveSupport::Notifications.instrument("redirect_to.action_controller") do |payload|
+ result = super
+ payload[:status] = response.status
+ payload[:location] = response.filtered_location
+ result
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/instrumentation.rb, line 64
-def redirect_to(*args)
- ActiveSupport::Notifications.instrument("redirect_to.action_controller") do |payload|
- result = super
- payload[:status] = response.status
- payload[:location] = response.filtered_location
- result
- end
-end
- # File actionpack/lib/action_controller/metal/instrumentation.rb, line 43
+ def render(*args)
+ render_output = nil
+ self.view_runtime = cleanup_view_runtime do
+ Benchmark.ms { render_output = super }
+ end
+ render_output
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/instrumentation.rb, line 43
-def render(*args)
- render_output = nil
- self.view_runtime = cleanup_view_runtime do
- Benchmark.ms { render_output = super }
- end
- render_output
-end
- # File actionpack/lib/action_controller/metal/instrumentation.rb, line 58
+ def send_data(data, options = {})
+ ActiveSupport::Notifications.instrument("send_data.action_controller", options) do
+ super
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/instrumentation.rb, line 58
-def send_data(data, options = {})
- ActiveSupport::Notifications.instrument("send_data.action_controller", options) do
- super
- end
-end
- # File actionpack/lib/action_controller/metal/instrumentation.rb, line 51
+ def send_file(path, options = {})
+ ActiveSupport::Notifications.instrument("send_file.action_controller",
+ options.merge(path: path)) do
+ super
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/instrumentation.rb, line 51
-def send_file(path, options = {})
- ActiveSupport::Notifications.instrument("send_file.action_controller",
- options.merge(path: path)) do
- super
- end
-end
- # File actionpack/lib/action_controller/metal/instrumentation.rb, line 92
+ def append_info_to_payload(payload) # :doc:
+ payload[:view_runtime] = view_runtime
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/instrumentation.rb, line 92
-def append_info_to_payload(payload) # :doc:
- payload[:view_runtime] = view_runtime
-end
- # File actionpack/lib/action_controller/metal/instrumentation.rb, line 86
+ def cleanup_view_runtime # :doc:
+ yield
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/instrumentation.rb, line 86
-def cleanup_view_runtime # :doc:
- yield
-end
- # File actionpack/lib/action_controller/metal/live.rb, line 295
+ def log_error(exception)
+ logger = ActionController::Base.logger
+ return unless logger
+
+ logger.fatal do
+ message = "\n#{exception.class} (#{exception.message}):\n".dup
+ message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
+ message << " " << exception.backtrace.join("\n ")
+ "#{message}\n\n"
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/live.rb, line 295
-def log_error(exception)
- logger = ActionController::Base.logger
- return unless logger
-
- logger.fatal do
- message = "\n#{exception.class} (#{exception.message}):\n".dup
- message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
- message << " " << exception.backtrace.join("\n ")
- "#{message}\n\n"
- end
-end
- # File actionpack/lib/action_controller/metal/live.rb, line 238
+ def process(name)
+ t1 = Thread.current
+ locals = t1.keys.map { |key| [key, t1[key]] }
+
+ error = nil
+ # This processes the action in a child thread. It lets us return the
+ # response code and headers back up the Rack stack, and still process
+ # the body in parallel with sending data to the client.
+ new_controller_thread {
+ ActiveSupport::Dependencies.interlock.running do
+ t2 = Thread.current
+
+ # Since we're processing the view in a different thread, copy the
+ # thread locals from the main thread to the child thread. :'(
+ locals.each { |k, v| t2[k] = v }
+
+ begin
+ super(name)
+ rescue => e
+ if @_response.committed?
+ begin
+ @_response.stream.write(ActionView::Base.streaming_completion_on_exception) if request.format == :html
+ @_response.stream.call_on_error
+ rescue => exception
+ log_error(exception)
+ ensure
+ log_error(e)
+ @_response.stream.close
+ end
+ else
+ error = e
+ end
+ ensure
+ @_response.commit!
+ end
+ end
+ }
+
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
+ @_response.await_commit
+ end
+
+ raise error if error
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/live.rb, line 238
-def process(name)
- t1 = Thread.current
- locals = t1.keys.map { |key| [key, t1[key]] }
-
- error = nil
- # This processes the action in a child thread. It lets us return the
- # response code and headers back up the Rack stack, and still process
- # the body in parallel with sending data to the client.
- new_controller_thread {
- ActiveSupport::Dependencies.interlock.running do
- t2 = Thread.current
-
- # Since we're processing the view in a different thread, copy the
- # thread locals from the main thread to the child thread. :'(
- locals.each { |k, v| t2[k] = v }
-
- begin
- super(name)
- rescue => e
- if @_response.committed?
- begin
- @_response.stream.write(ActionView::Base.streaming_completion_on_exception) if request.format == :html
- @_response.stream.call_on_error
- rescue => exception
- log_error(exception)
- ensure
- log_error(e)
- @_response.stream.close
- end
- else
- error = e
- end
- ensure
- @_response.commit!
- end
- end
- }
-
- ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
- @_response.await_commit
- end
-
- raise error if error
-end
- # File actionpack/lib/action_controller/metal/live.rb, line 307
+ def response_body=(body)
+ super
+ response.close if response
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/live.rb, line 307
-def response_body=(body)
- super
- response.close if response
-end
- # File actionpack/lib/action_controller/metal/live.rb, line 41
+ def make_response!(request)
+ if request.get_header("HTTP_VERSION") == "HTTP/1.0"
+ super
+ else
+ Live::Response.new.tap do |res|
+ res.request = request
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/live.rb, line 41
-def make_response!(request)
- if request.get_header("HTTP_VERSION") == "HTTP/1.0"
- super
- else
- Live::Response.new.tap do |res|
- res.request = request
- end
- end
-end
- # File actionpack/lib/action_controller/metal/live.rb, line 91
+ def initialize(stream, options = {})
+ @stream = stream
+ @options = options
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/live.rb, line 91
-def initialize(stream, options = {})
- @stream = stream
- @options = options
-end
- # File actionpack/lib/action_controller/metal/live.rb, line 96
+ def close
+ @stream.close
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/live.rb, line 96
-def close
- @stream.close
-end
- # File actionpack/lib/action_controller/metal/live.rb, line 100
+ def write(object, options = {})
+ case object
+ when String
+ perform_write(object, options)
+ else
+ perform_write(ActiveSupport::JSON.encode(object), options)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/live.rb, line 100
-def write(object, options = {})
- case object
- when String
- perform_write(object, options)
- else
- perform_write(ActiveSupport::JSON.encode(object), options)
- end
-end
- # File actionpack/lib/action_controller/log_subscriber.rb, line 37
+ def halted_callback(event)
+ info { "Filter chain halted as #{event.payload[:filter].inspect} rendered or redirected" }
+ end
- - Source: - -
-# File actionpack/lib/action_controller/log_subscriber.rb, line 37
-def halted_callback(event)
- info { "Filter chain halted as #{event.payload[:filter].inspect} rendered or redirected" }
-end
- # File actionpack/lib/action_controller/log_subscriber.rb, line 72
+ def logger
+ ActionController::Base.logger
+ end
- - Source: - -
-# File actionpack/lib/action_controller/log_subscriber.rb, line 72
-def logger
- ActionController::Base.logger
-end
- # File actionpack/lib/action_controller/log_subscriber.rb, line 19
+ def process_action(event)
+ info do
+ payload = event.payload
+ additions = ActionController::Base.log_process_action(payload)
+
+ status = payload[:status]
+ if status.nil? && payload[:exception].present?
+ exception_class_name = payload[:exception].first
+ status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
+ end
+ message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms".dup
+ message << " (#{additions.join(" | ".freeze)})" unless additions.empty?
+ message << "\n\n" if defined?(Rails.env) && Rails.env.development?
+
+ message
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/log_subscriber.rb, line 19
-def process_action(event)
- info do
- payload = event.payload
- additions = ActionController::Base.log_process_action(payload)
-
- status = payload[:status]
- if status.nil? && payload[:exception].present?
- exception_class_name = payload[:exception].first
- status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
- end
- message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms".dup
- message << " (#{additions.join(" | ".freeze)})" unless additions.empty?
- message << "\n\n" if defined?(Rails.env) && Rails.env.development?
-
- message
- end
-end
- # File actionpack/lib/action_controller/log_subscriber.rb, line 45
+ def redirect_to(event)
+ info { "Redirected to #{event.payload[:location]}" }
+ end
- - Source: - -
-# File actionpack/lib/action_controller/log_subscriber.rb, line 45
-def redirect_to(event)
- info { "Redirected to #{event.payload[:location]}" }
-end
- # File actionpack/lib/action_controller/log_subscriber.rb, line 49
+ def send_data(event)
+ info { "Sent data #{event.payload[:filename]} (#{event.duration.round(1)}ms)" }
+ end
- - Source: - -
-# File actionpack/lib/action_controller/log_subscriber.rb, line 49
-def send_data(event)
- info { "Sent data #{event.payload[:filename]} (#{event.duration.round(1)}ms)" }
-end
- # File actionpack/lib/action_controller/log_subscriber.rb, line 41
+ def send_file(event)
+ info { "Sent file #{event.payload[:path]} (#{event.duration.round(1)}ms)" }
+ end
- - Source: - -
-# File actionpack/lib/action_controller/log_subscriber.rb, line 41
-def send_file(event)
- info { "Sent file #{event.payload[:path]} (#{event.duration.round(1)}ms)" }
-end
- # File actionpack/lib/action_controller/log_subscriber.rb, line 7
+ def start_processing(event)
+ return unless logger.info?
+
+ payload = event.payload
+ params = payload[:params].except(*INTERNAL_PARAMS)
+ format = payload[:format]
+ format = format.to_s.upcase if format.is_a?(Symbol)
+
+ info "Processing by #{payload[:controller]}##{payload[:action]} as #{format}"
+ info " Parameters: #{params.inspect}" unless params.empty?
+ end
- - Source: - -
-# File actionpack/lib/action_controller/log_subscriber.rb, line 7
-def start_processing(event)
- return unless logger.info?
-
- payload = event.payload
- params = payload[:params].except(*INTERNAL_PARAMS)
- format = payload[:format]
- format = format.to_s.upcase if format.is_a?(Symbol)
-
- info "Processing by #{payload[:controller]}##{payload[:action]} as #{format}"
- info " Parameters: #{params.inspect}" unless params.empty?
-end
- # File actionpack/lib/action_controller/log_subscriber.rb, line 53
+ def unpermitted_parameters(event)
+ debug do
+ unpermitted_keys = event.payload[:keys]
+ "Unpermitted parameter#{'s' if unpermitted_keys.size > 1}: #{unpermitted_keys.map { |e| ":#{e}" }.join(", ")}"
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/log_subscriber.rb, line 53
-def unpermitted_parameters(event)
- debug do
- unpermitted_keys = event.payload[:keys]
- "Unpermitted parameter#{'s' if unpermitted_keys.size > 1}: #{unpermitted_keys.map { |e| ":#{e}" }.join(", ")}"
- end
-end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 232
-def self.action(name)
- app = lambda { |env|
- req = ActionDispatch::Request.new(env)
- res = make_response! req
- new.dispatch(name, req, res)
- }
-
- if middleware_stack.any?
- middleware_stack.build(name, app)
- else
- app
- end
-end
- # File actionpack/lib/action_controller/metal.rb, line 232
+ def self.action(name)
+ app = lambda { |env|
+ req = ActionDispatch::Request.new(env)
+ res = make_response! req
+ new.dispatch(name, req, res)
+ }
+
+ if middleware_stack.any?
+ middleware_stack.build(name, app)
+ else
+ app
+ end
+ end
+
+ 🔎 See on GitHub
+
+ # File actionpack/lib/action_controller/metal.rb, line 129
+ def self.controller_name
+ @controller_name ||= name.demodulize.sub(/Controller$/, "").underscore
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 129
-def self.controller_name
- @controller_name ||= name.demodulize.sub(/Controller$/, "").underscore
-end
- # File actionpack/lib/action_controller/metal.rb, line 248
+ def self.dispatch(name, req, res)
+ if middleware_stack.any?
+ middleware_stack.build(name) { |env| new.dispatch(name, req, res) }.call req.env
+ else
+ new.dispatch(name, req, res)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 248
-def self.dispatch(name, req, res)
- if middleware_stack.any?
- middleware_stack.build(name) { |env| new.dispatch(name, req, res) }.call req.env
- else
- new.dispatch(name, req, res)
- end
-end
- # File actionpack/lib/action_controller/metal.rb, line 133
+ def self.make_response!(request)
+ ActionDispatch::Response.new.tap do |res|
+ res.request = request
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 133
-def self.make_response!(request)
- ActionDispatch::Response.new.tap do |res|
- res.request = request
- end
-end
- # File actionpack/lib/action_controller/metal.rb, line 227
+ def self.middleware
+ middleware_stack
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 227
-def self.middleware
- middleware_stack
-end
- # File actionpack/lib/action_controller/metal.rb, line 153
+ def initialize
+ @_request = nil
+ @_response = nil
+ @_routes = nil
+ super
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 153
-def initialize
- @_request = nil
- @_response = nil
- @_routes = nil
- super
-end
- # File actionpack/lib/action_controller/metal.rb, line 222
+ def self.use(*args, &block)
+ middleware_stack.use(*args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 222
-def self.use(*args, &block)
- middleware_stack.use(*args, &block)
-end
- # File actionpack/lib/action_controller/metal.rb, line 144
+ def controller_name
+ self.class.controller_name
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 144
-def controller_name
- self.class.controller_name
-end
- # File actionpack/lib/action_controller/metal.rb, line 160
+ def params
+ @_params ||= request.parameters
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 160
-def params
- @_params ||= request.parameters
-end
- # File actionpack/lib/action_controller/metal.rb, line 164
+ def params=(val)
+ @_params = val
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 164
-def params=(val)
- @_params = val
-end
- # File actionpack/lib/action_controller/metal.rb, line 184
+ def performed?
+ response_body || response.committed?
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 184
-def performed?
- response_body || response.committed?
-end
- # File actionpack/lib/action_controller/metal.rb, line 209
+ def reset_session
+ @_request.reset_session
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 209
-def reset_session
- @_request.reset_session
-end
- # File actionpack/lib/action_controller/metal.rb, line 175
+ def response_body=(body)
+ body = [body] unless body.nil? || body.respond_to?(:each)
+ response.reset_body!
+ return unless body
+ response.body = body
+ super
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 175
-def response_body=(body)
- body = [body] unless body.nil? || body.respond_to?(:each)
- response.reset_body!
- return unless body
- response.body = body
- super
-end
- # File actionpack/lib/action_controller/metal.rb, line 171
+ def url_for(string)
+ string
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal.rb, line 171
-def url_for(string)
- string
-end
- # File actionpack/lib/action_controller/metal/mime_responds.rb, line 193
+ def respond_to(*mimes)
+ raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given?
+
+ collector = Collector.new(mimes, request.variant)
+ yield collector if block_given?
+
+ if format = collector.negotiate_format(request)
+ _process_format(format)
+ _set_rendered_content_type format
+ response = collector.response
+ response.call if response
+ else
+ raise ActionController::UnknownFormat
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/mime_responds.rb, line 193
-def respond_to(*mimes)
- raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given?
-
- collector = Collector.new(mimes, request.variant)
- yield collector if block_given?
-
- if format = collector.negotiate_format(request)
- _process_format(format)
- _set_rendered_content_type format
- response = collector.response
- response.call if response
- else
- raise ActionController::UnknownFormat
- end
-end
- # File actionpack/lib/action_controller/metal/mime_responds.rb, line 235
+ def initialize(mimes, variant = nil)
+ @responses = {}
+ @variant = variant
+
+ mimes.each { |mime| @responses[Mime[mime]] = nil }
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/mime_responds.rb, line 235
-def initialize(mimes, variant = nil)
- @responses = {}
- @variant = variant
-
- mimes.each { |mime| @responses[Mime[mime]] = nil }
-end
- # File actionpack/lib/action_controller/metal/mime_responds.rb, line 242
+ def any(*args, &block)
+ if args.any?
+ args.each { |type| send(type, &block) }
+ else
+ custom(Mime::ALL, &block)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/mime_responds.rb, line 242
-def any(*args, &block)
- if args.any?
- args.each { |type| send(type, &block) }
- else
- custom(Mime::ALL, &block)
- end
-end
- # File actionpack/lib/action_controller/metal/mime_responds.rb, line 251
+ def custom(mime_type, &block)
+ mime_type = Mime::Type.lookup(mime_type.to_s) unless mime_type.is_a?(Mime::Type)
+ @responses[mime_type] ||= if block_given?
+ block
+ else
+ VariantCollector.new(@variant)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/mime_responds.rb, line 251
-def custom(mime_type, &block)
- mime_type = Mime::Type.lookup(mime_type.to_s) unless mime_type.is_a?(Mime::Type)
- @responses[mime_type] ||= if block_given?
- block
- else
- VariantCollector.new(@variant)
- end
-end
- # File actionpack/lib/action_controller/metal/mime_responds.rb, line 273
+ def negotiate_format(request)
+ @format = request.negotiate_mime(@responses.keys)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/mime_responds.rb, line 273
-def negotiate_format(request)
- @format = request.negotiate_mime(@responses.keys)
-end
- # File actionpack/lib/action_controller/metal/mime_responds.rb, line 260
+ def response
+ response = @responses.fetch(format, @responses[Mime::ALL])
+ if response.is_a?(VariantCollector) # `format.html.phone` - variant inline syntax
+ response.variant
+ elsif response.nil? || response.arity == 0 # `format.html` - just a format, call its block
+ response
+ else # `format.html{ |variant| variant.phone }` - variant block syntax
+ variant_collector = VariantCollector.new(@variant)
+ response.call(variant_collector) # call format block with variants collector
+ variant_collector.variant
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/mime_responds.rb, line 260
-def response
- response = @responses.fetch(format, @responses[Mime::ALL])
- if response.is_a?(VariantCollector) # `format.html.phone` - variant inline syntax
- response.variant
- elsif response.nil? || response.arity == 0 # `format.html` - just a format, call its block
- response
- else # `format.html{ |variant| variant.phone }` - variant block syntax
- variant_collector = VariantCollector.new(@variant)
- response.call(variant_collector) # call format block with variants collector
- variant_collector.variant
- end
-end
- # File actionpack/lib/action_controller/metal/renderers.rb, line 18
+ def initialize(format)
+ super "No renderer defined for format: #{format}"
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/renderers.rb, line 18
-def initialize(format)
- super "No renderer defined for format: #{format}"
-end
- # File actionpack/lib/action_controller/metal/parameter_encoding.rb, line 46
+ def skip_parameter_encoding(action)
+ @_parameter_encodings[action.to_s] = true
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/parameter_encoding.rb, line 46
-def skip_parameter_encoding(action)
- @_parameter_encodings[action.to_s] = true
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 235
+ def initialize(parameters = {})
+ @parameters = parameters.with_indifferent_access
+ @permitted = self.class.permit_all_parameters
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 235
-def initialize(parameters = {})
- @parameters = parameters.with_indifferent_access
- @permitted = self.class.permit_all_parameters
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 242
+ def ==(other)
+ if other.respond_to?(:permitted?)
+ permitted? == other.permitted? && parameters == other.parameters
+ else
+ @parameters == other
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 242
-def ==(other)
- if other.respond_to?(:permitted?)
- permitted? == other.permitted? && parameters == other.parameters
- else
- @parameters == other
- end
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 553
+ def [](key)
+ convert_hashes_to_parameters(key, @parameters[key])
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 553
-def [](key)
- convert_hashes_to_parameters(key, @parameters[key])
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 559
+ def []=(key, value)
+ @parameters[key] = value
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 559
-def []=(key, value)
- @parameters[key] = value
-end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 129
-
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 352
+ def converted_arrays
+ @converted_arrays ||= Set.new
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 352
-def converted_arrays
- @converted_arrays ||= Set.new
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 792
+ def deep_dup
+ self.class.new(@parameters.deep_dup).tap do |duplicate|
+ duplicate.permitted = @permitted
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 792
-def deep_dup
- self.class.new(@parameters.deep_dup).tap do |duplicate|
- duplicate.permitted = @permitted
- end
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 685
+ def delete(key, &block)
+ convert_value_to_parameters(@parameters.delete(key, &block))
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 685
-def delete(key, &block)
- convert_value_to_parameters(@parameters.delete(key, &block))
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 598
+ def dig(*keys)
+ convert_hashes_to_parameters(keys.first, @parameters[keys.first])
+ @parameters.dig(*keys)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 598
-def dig(*keys)
- convert_hashes_to_parameters(keys.first, @parameters[keys.first])
- @parameters.dig(*keys)
-end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 336
-def each_pair(&block)
- @parameters.each_pair do |key, value|
- yield [key, convert_hashes_to_parameters(key, value)]
- end
+
+
+
+ 📝 Source code
+
- self
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 336
+ def each_pair(&block)
+ @parameters.each_pair do |key, value|
+ yield [key, convert_hashes_to_parameters(key, value)]
+ end
+
+ self
+ end
+
+ 🔎 See on GitHub
+
+
+
+
- Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 137
-
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 628
+ def except(*keys)
+ new_instance_with_inherited_permitted_status(@parameters.except(*keys))
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 628
-def except(*keys)
- new_instance_with_inherited_permitted_status(@parameters.except(*keys))
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 637
+ def extract!(*keys)
+ new_instance_with_inherited_permitted_status(@parameters.extract!(*keys))
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 637
-def extract!(*keys)
- new_instance_with_inherited_permitted_status(@parameters.extract!(*keys))
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 576
+ def fetch(key, *args)
+ convert_value_to_parameters(
+ @parameters.fetch(key) {
+ if block_given?
+ yield
+ else
+ args.fetch(0) { raise ActionController::ParameterMissing.new(key) }
+ end
+ }
+ )
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 576
-def fetch(key, *args)
- convert_value_to_parameters(
- @parameters.fetch(key) {
- if block_given?
- yield
- else
- args.fetch(0) { raise ActionController::ParameterMissing.new(key) }
- end
- }
- )
-end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 145
-
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 153
-
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 161
-
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 760
+ def inspect
+ "<#{self.class} #{@parameters} permitted: #{@permitted}>"
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 760
-def inspect
- "<#{self.class} #{@parameters} permitted: #{@permitted}>"
-end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 169
-
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 177
-
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 723
+ def merge(other_hash)
+ new_instance_with_inherited_permitted_status(
+ @parameters.merge(other_hash.to_h)
+ )
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 723
-def merge(other_hash)
- new_instance_with_inherited_permitted_status(
- @parameters.merge(other_hash.to_h)
- )
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 731
+ def merge!(other_hash)
+ @parameters.merge!(other_hash.to_h)
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 731
-def merge!(other_hash)
- @parameters.merge!(other_hash.to_h)
- self
-end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 530
-def permit(*filters)
- params = self.class.new
+
+
+
+ 📝 Source code
+
- filters.flatten.each do |filter|
- case filter
- when Symbol, String
- permitted_scalar_filter(params, filter)
- when Hash
- hash_filter(params, filter)
- end
- end
+ # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 530
+ def permit(*filters)
+ params = self.class.new
- unpermitted_parameters!(params) if self.class.action_on_unpermitted_parameters
+ filters.flatten.each do |filter|
+ case filter
+ when Symbol, String
+ permitted_scalar_filter(params, filter)
+ when Hash
+ hash_filter(params, filter)
+ end
+ end
- params.permit!
-end
-
- Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 378
-def permit!
- each_pair do |key, value|
- Array.wrap(value).flatten.each do |v|
- v.permit! if v.respond_to? :permit!
- end
- end
+
+
+
+ 📝 Source code
+
- @permitted = true
- self
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 378
+ def permit!
+ each_pair do |key, value|
+ Array.wrap(value).flatten.each do |v|
+ v.permit! if v.respond_to? :permit!
+ end
+ end
+
+ @permitted = true
+ self
+ end
+
+ 🔎 See on GitHub
+
+
+
+
# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 362
+ def permitted?
+ @permitted
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 362
-def permitted?
- @permitted
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 704
+ def reject(&block)
+ new_instance_with_inherited_permitted_status(@parameters.reject(&block))
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 704
-def reject(&block)
- new_instance_with_inherited_permitted_status(@parameters.reject(&block))
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 709
+ def reject!(&block)
+ @parameters.reject!(&block)
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 709
-def reject!(&block)
- @parameters.reject!(&block)
- self
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 439
+ def require(key)
+ return key.map { |k| require(k) } if key.is_a?(Array)
+ value = self[key]
+ if value.present? || value == false
+ value
+ else
+ raise ParameterMissing.new(key)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 439
-def require(key)
- return key.map { |k| require(k) } if key.is_a?(Array)
- value = self[key]
- if value.present? || value == false
- value
- else
- raise ParameterMissing.new(key)
- end
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 738
+ def reverse_merge(other_hash)
+ new_instance_with_inherited_permitted_status(
+ other_hash.to_h.merge(@parameters)
+ )
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 738
-def reverse_merge(other_hash)
- new_instance_with_inherited_permitted_status(
- other_hash.to_h.merge(@parameters)
- )
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 747
+ def reverse_merge!(other_hash)
+ @parameters.merge!(other_hash.to_h) { |key, left, right| left }
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 747
-def reverse_merge!(other_hash)
- @parameters.merge!(other_hash.to_h) { |key, left, right| left }
- self
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 691
+ def select(&block)
+ new_instance_with_inherited_permitted_status(@parameters.select(&block))
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 691
-def select(&block)
- new_instance_with_inherited_permitted_status(@parameters.select(&block))
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 696
+ def select!(&block)
+ @parameters.select!(&block)
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 696
-def select!(&block)
- @parameters.select!(&block)
- self
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 611
+ def slice(*keys)
+ new_instance_with_inherited_permitted_status(@parameters.slice(*keys))
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 611
-def slice(*keys)
- new_instance_with_inherited_permitted_status(@parameters.slice(*keys))
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 617
+ def slice!(*keys)
+ @parameters.slice!(*keys)
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 617
-def slice!(*keys)
- @parameters.slice!(*keys)
- self
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 262
+ def to_h
+ if permitted?
+ convert_parameters_to_hashes(@parameters, :to_h)
+ else
+ raise UnfilteredParameters
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 262
-def to_h
- if permitted?
- convert_parameters_to_hashes(@parameters, :to_h)
- else
- raise UnfilteredParameters
- end
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 282
+ def to_hash
+ to_h.to_hash
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 282
-def to_hash
- to_h.to_hash
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 314
+ def to_query(*args)
+ to_h.to_query(*args)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 314
-def to_query(*args)
- to_h.to_query(*args)
-end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 185
-
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 329
+ def to_unsafe_h
+ convert_parameters_to_hashes(@parameters, :to_unsafe_h)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 329
-def to_unsafe_h
- convert_parameters_to_hashes(@parameters, :to_unsafe_h)
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 664
+ def transform_keys(&block)
+ if block
+ new_instance_with_inherited_permitted_status(
+ @parameters.transform_keys(&block)
+ )
+ else
+ @parameters.transform_keys
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 664
-def transform_keys(&block)
- if block
- new_instance_with_inherited_permitted_status(
- @parameters.transform_keys(&block)
- )
- else
- @parameters.transform_keys
- end
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 676
+ def transform_keys!(&block)
+ @parameters.transform_keys!(&block)
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 676
-def transform_keys!(&block)
- @parameters.transform_keys!(&block)
- self
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 647
+ def transform_values
+ return to_enum(:transform_values) unless block_given?
+ new_instance_with_inherited_permitted_status(
+ @parameters.transform_values { |v| yield convert_value_to_parameters(v) }
+ )
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 647
-def transform_values
- return to_enum(:transform_values) unless block_given?
- new_instance_with_inherited_permitted_status(
- @parameters.transform_values { |v| yield convert_value_to_parameters(v) }
- )
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 656
+ def transform_values!
+ return to_enum(:transform_values!) unless block_given?
+ @parameters.transform_values! { |v| yield convert_value_to_parameters(v) }
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 656
-def transform_values!
- return to_enum(:transform_values!) unless block_given?
- @parameters.transform_values! { |v| yield convert_value_to_parameters(v) }
- self
-end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 193
-
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 207
-delegate :keys, :key?, :has_key?, :values, :has_value?, :value?, :empty?, :include?,
- :as_json, :to_s, to: :@parameters
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 207
+ delegate :keys, :key?, :has_key?, :values, :has_value?, :value?, :empty?, :include?,
+ :as_json, :to_s, to: :@parameters
-
# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 717
+ def values_at(*keys)
+ convert_value_to_parameters(@parameters.values_at(*keys))
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 717
-def values_at(*keys)
- convert_value_to_parameters(@parameters.values_at(*keys))
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 805
+ def fields_for_style?
+ @parameters.all? { |k, v| k =~ /\A-?\d+\z/ && (v.is_a?(Hash) || v.is_a?(Parameters)) }
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 805
-def fields_for_style?
- @parameters.all? { |k, v| k =~ /\A-?\d+\z/ && (v.is_a?(Hash) || v.is_a?(Parameters)) }
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 801
+ def permitted=(new_permitted)
+ @permitted = new_permitted
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 801
-def permitted=(new_permitted)
- @permitted = new_permitted
-end
- # File actionpack/lib/action_controller/metal/params_wrapper.rb, line 176
+ def _set_wrapper_options(options)
+ self._wrapper_options = Options.from_hash(options)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/params_wrapper.rb, line 176
-def _set_wrapper_options(options)
- self._wrapper_options = Options.from_hash(options)
-end
- # File actionpack/lib/action_controller/metal/params_wrapper.rb, line 231
+ def inherited(klass)
+ if klass._wrapper_options.format.any?
+ params = klass._wrapper_options.dup
+ params.klass = klass
+ klass._wrapper_options = params
+ end
+ super
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/params_wrapper.rb, line 231
-def inherited(klass)
- if klass._wrapper_options.format.any?
- params = klass._wrapper_options.dup
- params.klass = klass
- klass._wrapper_options = params
- end
- super
-end
- # File actionpack/lib/action_controller/railties/helpers.rb, line 6
+ def inherited(klass)
+ super
+ return unless klass.respond_to?(:helpers_path=)
+
+ if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_helpers_paths) }
+ paths = namespace.railtie_helpers_paths
+ else
+ paths = ActionController::Helpers.helpers_path
+ end
+
+ klass.helpers_path = paths
+
+ if klass.superclass == ActionController::Base && ActionController::Base.include_all_helpers
+ klass.helper :all
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/railties/helpers.rb, line 6
-def inherited(klass)
- super
- return unless klass.respond_to?(:helpers_path=)
-
- if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_helpers_paths) }
- paths = namespace.railtie_helpers_paths
- else
- paths = ActionController::Helpers.helpers_path
- end
-
- klass.helpers_path = paths
-
- if klass.superclass == ActionController::Base && ActionController::Base.include_all_helpers
- klass.helper :all
- end
-end
- # File actionpack/lib/action_controller/metal/redirecting.rb, line 90
+ def redirect_back(fallback_location:, allow_other_host: true, **args)
+ referer = request.headers["Referer"]
+ redirect_to_referer = referer && (allow_other_host || _url_host_allowed?(referer))
+ redirect_to redirect_to_referer ? referer : fallback_location, **args
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/redirecting.rb, line 90
-def redirect_back(fallback_location:, allow_other_host: true, **args)
- referer = request.headers["Referer"]
- redirect_to_referer = referer && (allow_other_host || _url_host_allowed?(referer))
- redirect_to redirect_to_referer ? referer : fallback_location, **args
-end
- # File actionpack/lib/action_controller/metal/redirecting.rb, line 58
+ def redirect_to(options = {}, response_status = {})
+ raise ActionControllerError.new("Cannot redirect to nil!") unless options
+ raise AbstractController::DoubleRenderError if response_body
+
+ self.status = _extract_redirect_to_status(options, response_status)
+ self.location = _compute_redirect_to_location(request, options)
+ self.response_body = "<html><body>You are being <a href=\"#{ERB::Util.unwrapped_html_escape(response.location)}\">redirected</a>.</body></html>"
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/redirecting.rb, line 58
-def redirect_to(options = {}, response_status = {})
- raise ActionControllerError.new("Cannot redirect to nil!") unless options
- raise AbstractController::DoubleRenderError if response_body
-
- self.status = _extract_redirect_to_status(options, response_status)
- self.location = _compute_redirect_to_location(request, options)
- self.response_body = "<html><body>You are being <a href=\"#{ERB::Util.unwrapped_html_escape(response.location)}\">redirected</a>.</body></html>"
-end
- # File actionpack/lib/action_controller/renderer.rb, line 50
+ def self.for(controller, env = {}, defaults = DEFAULTS.dup)
+ new(controller, env, defaults)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/renderer.rb, line 50
-def self.for(controller, env = {}, defaults = DEFAULTS.dup)
- new(controller, env, defaults)
-end
- # File actionpack/lib/action_controller/renderer.rb, line 67
+ def initialize(controller, env, defaults)
+ @controller = controller
+ @defaults = defaults
+ @env = normalize_keys defaults.merge(env)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/renderer.rb, line 67
-def initialize(controller, env, defaults)
- @controller = controller
- @defaults = defaults
- @env = normalize_keys defaults.merge(env)
-end
- # File actionpack/lib/action_controller/renderer.rb, line 55
+ def new(env = {})
+ self.class.new controller, env, defaults
+ end
- - Source: - -
-# File actionpack/lib/action_controller/renderer.rb, line 55
-def new(env = {})
- self.class.new controller, env, defaults
-end
- # File actionpack/lib/action_controller/renderer.rb, line 74
+ def render(*args)
+ raise "missing controller" unless controller
+
+ request = ActionDispatch::Request.new @env
+ request.routes = controller._routes
+
+ instance = controller.new
+ instance.set_request! request
+ instance.set_response! controller.make_response!(request)
+ instance.render_to_string(*args)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/renderer.rb, line 74
-def render(*args)
- raise "missing controller" unless controller
-
- request = ActionDispatch::Request.new @env
- request.routes = controller._routes
-
- instance = controller.new
- instance.set_request! request
- instance.set_response! controller.make_response!(request)
- instance.render_to_string(*args)
-end
- # File actionpack/lib/action_controller/renderer.rb, line 60
+ def with_defaults(defaults)
+ self.class.new controller, @env, self.defaults.merge(defaults)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/renderer.rb, line 60
-def with_defaults(defaults)
- self.class.new controller, @env, self.defaults.merge(defaults)
-end
- # File actionpack/lib/action_controller/metal/renderers.rb, line 91
+ def self._render_with_renderer_method_name(key)
+ "_render_with_renderer_#{key}"
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/renderers.rb, line 91
-def self._render_with_renderer_method_name(key)
- "_render_with_renderer_#{key}"
-end
- # File actionpack/lib/action_controller/metal/renderers.rb, line 75
+ def self.add(key, &block)
+ define_method(_render_with_renderer_method_name(key), &block)
+ RENDERERS << key.to_sym
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/renderers.rb, line 75
-def self.add(key, &block)
- define_method(_render_with_renderer_method_name(key), &block)
- RENDERERS << key.to_sym
-end
- # File actionpack/lib/action_controller/metal/renderers.rb, line 85
+ def self.remove(key)
+ RENDERERS.delete(key.to_sym)
+ method_name = _render_with_renderer_method_name(key)
+ remove_possible_method(method_name)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/renderers.rb, line 85
-def self.remove(key)
- RENDERERS.delete(key.to_sym)
- method_name = _render_with_renderer_method_name(key)
- remove_possible_method(method_name)
-end
- # File actionpack/lib/action_controller/metal/renderers.rb, line 145
+ def _render_to_body_with_renderer(options)
+ _renderers.each do |name|
+ if options.key?(name)
+ _process_options(options)
+ method_name = Renderers._render_with_renderer_method_name(name)
+ return send(method_name, options.delete(name), options)
+ end
+ end
+ nil
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/renderers.rb, line 145
-def _render_to_body_with_renderer(options)
- _renderers.each do |name|
- if options.key?(name)
- _process_options(options)
- method_name = Renderers._render_with_renderer_method_name(name)
- return send(method_name, options.delete(name), options)
- end
- end
- nil
-end
- # File actionpack/lib/action_controller/metal/renderers.rb, line 141
+ def render_to_body(options)
+ _render_to_body_with_renderer(options) || super
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/renderers.rb, line 141
-def render_to_body(options)
- _render_to_body_with_renderer(options) || super
-end
- # File actionpack/lib/action_controller/metal/renderers.rb, line 129
+ def use_renderers(*args)
+ renderers = _renderers + args
+ self._renderers = renderers.freeze
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/renderers.rb, line 129
-def use_renderers(*args)
- renderers = _renderers + args
- self._renderers = renderers.freeze
-end
- # File actionpack/lib/action_controller/metal/rendering.rb, line 51
+ def render_to_body(options = {})
+ super || _render_in_priorities(options) || " "
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/rendering.rb, line 51
-def render_to_body(options = {})
- super || _render_in_priorities(options) || " "
-end
- # File actionpack/lib/action_controller/metal/rendering.rb, line 40
+ def render_to_string(*)
+ result = super
+ if result.respond_to?(:each)
+ string = "".dup
+ result.each { |r| string << r }
+ string
+ else
+ result
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/rendering.rb, line 40
-def render_to_string(*)
- result = super
- if result.respond_to?(:each)
- string = "".dup
- result.each { |r| string << r }
- string
- else
- result
- end
-end
- # File actionpack/lib/action_controller/metal/rendering.rb, line 21
+ def inherited(klass)
+ klass.setup_renderer!
+ super
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/rendering.rb, line 21
-def inherited(klass)
- klass.setup_renderer!
- super
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 299
+ def any_authenticity_token_valid? # :doc:
+ request_authenticity_tokens.any? do |token|
+ valid_authenticity_token?(session, token)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 299
-def any_authenticity_token_valid? # :doc:
- request_authenticity_tokens.any? do |token|
- valid_authenticity_token?(session, token)
- end
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 385
+ def compare_with_global_token(token, session) # :doc:
+ ActiveSupport::SecurityUtils.fixed_length_secure_compare(token, global_csrf_token(session))
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 385
-def compare_with_global_token(token, session) # :doc:
- ActiveSupport::SecurityUtils.fixed_length_secure_compare(token, global_csrf_token(session))
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 381
+ def compare_with_real_token(token, session) # :doc:
+ ActiveSupport::SecurityUtils.fixed_length_secure_compare(token, real_csrf_token(session))
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 381
-def compare_with_real_token(token, session) # :doc:
- ActiveSupport::SecurityUtils.fixed_length_secure_compare(token, real_csrf_token(session))
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 419
+ def csrf_token_hmac(session, identifier) # :doc:
+ OpenSSL::HMAC.digest(
+ OpenSSL::Digest::SHA256.new,
+ real_csrf_token(session),
+ identifier
+ )
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 419
-def csrf_token_hmac(session, identifier) # :doc:
- OpenSSL::HMAC.digest(
- OpenSSL::Digest::SHA256.new,
- real_csrf_token(session),
- identifier
- )
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 434
+ def form_authenticity_param # :doc:
+ params[request_forgery_protection_token]
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 434
-def form_authenticity_param # :doc:
- params[request_forgery_protection_token]
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 415
+ def global_csrf_token(session) # :doc:
+ csrf_token_hmac(session, GLOBAL_CSRF_TOKEN_IDENTIFIER)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 415
-def global_csrf_token(session) # :doc:
- csrf_token_hmac(session, GLOBAL_CSRF_TOKEN_IDENTIFIER)
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 246
+ def handle_unverified_request # :doc:
+ forgery_protection_strategy.new(self).handle_unverified_request
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 246
-def handle_unverified_request # :doc:
- forgery_protection_strategy.new(self).handle_unverified_request
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 271
+ def mark_for_same_origin_verification! # :doc:
+ @marked_for_same_origin_verification = request.get?
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 271
-def mark_for_same_origin_verification! # :doc:
- @marked_for_same_origin_verification = request.get?
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 277
+ def marked_for_same_origin_verification? # :doc:
+ @marked_for_same_origin_verification ||= false
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 277
-def marked_for_same_origin_verification? # :doc:
- @marked_for_same_origin_verification ||= false
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 374
+ def mask_token(raw_token) # :doc:
+ one_time_pad = SecureRandom.random_bytes(AUTHENTICITY_TOKEN_LENGTH)
+ encrypted_csrf_token = xor_byte_strings(one_time_pad, raw_token)
+ masked_token = one_time_pad + encrypted_csrf_token
+ encode_csrf_token(masked_token)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 374
-def mask_token(raw_token) # :doc:
- one_time_pad = SecureRandom.random_bytes(AUTHENTICITY_TOKEN_LENGTH)
- encrypted_csrf_token = xor_byte_strings(one_time_pad, raw_token)
- masked_token = one_time_pad + encrypted_csrf_token
- encode_csrf_token(masked_token)
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 318
+ def masked_authenticity_token(session, form_options: {}) # :doc:
+ action, method = form_options.values_at(:action, :method)
+
+ raw_token = if per_form_csrf_tokens && action && method
+ action_path = normalize_action_path(action)
+ per_form_csrf_token(session, action_path, method)
+ else
+ global_csrf_token(session)
+ end
+
+ mask_token(raw_token)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 318
-def masked_authenticity_token(session, form_options: {}) # :doc:
- action, method = form_options.values_at(:action, :method)
-
- raw_token = if per_form_csrf_tokens && action && method
- action_path = normalize_action_path(action)
- per_form_csrf_token(session, action_path, method)
- else
- global_csrf_token(session)
- end
-
- mask_token(raw_token)
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 282
+ def non_xhr_javascript_response? # :doc:
+ content_type =~ %r(\Atext/javascript) && !request.xhr?
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 282
-def non_xhr_javascript_response? # :doc:
- content_type =~ %r(\Atext/javascript) && !request.xhr?
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 464
+ def normalize_action_path(action_path) # :doc:
+ uri = URI.parse(action_path)
+ uri.path.chomp("/")
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 464
-def normalize_action_path(action_path) # :doc:
- uri = URI.parse(action_path)
- uri.path.chomp("/")
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 408
+ def per_form_csrf_token(session, action_path, method) # :doc:
+ csrf_token_hmac(session, [action_path, method.downcase].join("#"))
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 408
-def per_form_csrf_token(session, action_path, method) # :doc:
- csrf_token_hmac(session, [action_path, method.downcase].join("#"))
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 439
+ def protect_against_forgery? # :doc:
+ allow_forgery_protection
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 439
-def protect_against_forgery? # :doc:
- allow_forgery_protection
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 403
+ def real_csrf_token(session) # :doc:
+ session[:_csrf_token] ||= generate_csrf_token
+ decode_csrf_token(session[:_csrf_token])
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 403
-def real_csrf_token(session) # :doc:
- session[:_csrf_token] ||= generate_csrf_token
- decode_csrf_token(session[:_csrf_token])
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 306
+ def request_authenticity_tokens # :doc:
+ [form_authenticity_param, request.x_csrf_token]
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 306
-def request_authenticity_tokens # :doc:
- [form_authenticity_param, request.x_csrf_token]
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 366
+ def unmask_token(masked_token) # :doc:
+ # Split the token into the one-time pad and the encrypted
+ # value and decrypt it.
+ one_time_pad = masked_token[0...AUTHENTICITY_TOKEN_LENGTH]
+ encrypted_csrf_token = masked_token[AUTHENTICITY_TOKEN_LENGTH..-1]
+ xor_byte_strings(one_time_pad, encrypted_csrf_token)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 366
-def unmask_token(masked_token) # :doc:
- # Split the token into the one-time pad and the encrypted
- # value and decrypt it.
- one_time_pad = masked_token[0...AUTHENTICITY_TOKEN_LENGTH]
- encrypted_csrf_token = masked_token[AUTHENTICITY_TOKEN_LENGTH..-1]
- xor_byte_strings(one_time_pad, encrypted_csrf_token)
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 334
+ def valid_authenticity_token?(session, encoded_masked_token) # :doc:
+ if encoded_masked_token.nil? || encoded_masked_token.empty? || !encoded_masked_token.is_a?(String)
+ return false
+ end
+
+ begin
+ masked_token = decode_csrf_token(encoded_masked_token)
+ rescue ArgumentError # encoded_masked_token is invalid Base64
+ return false
+ end
+
+ # See if it's actually a masked token or not. In order to
+ # deploy this code, we should be able to handle any unmasked
+ # tokens that we've issued without error.
+
+ if masked_token.length == AUTHENTICITY_TOKEN_LENGTH
+ # This is actually an unmasked token. This is expected if
+ # you have just upgraded to masked tokens, but should stop
+ # happening shortly after installing this gem.
+ compare_with_real_token masked_token, session
+
+ elsif masked_token.length == AUTHENTICITY_TOKEN_LENGTH * 2
+ csrf_token = unmask_token(masked_token)
+
+ compare_with_global_token(csrf_token, session) ||
+ compare_with_real_token(csrf_token, session) ||
+ valid_per_form_csrf_token?(csrf_token, session)
+ else
+ false # Token is malformed.
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 334
-def valid_authenticity_token?(session, encoded_masked_token) # :doc:
- if encoded_masked_token.nil? || encoded_masked_token.empty? || !encoded_masked_token.is_a?(String)
- return false
- end
-
- begin
- masked_token = decode_csrf_token(encoded_masked_token)
- rescue ArgumentError # encoded_masked_token is invalid Base64
- return false
- end
-
- # See if it's actually a masked token or not. In order to
- # deploy this code, we should be able to handle any unmasked
- # tokens that we've issued without error.
-
- if masked_token.length == AUTHENTICITY_TOKEN_LENGTH
- # This is actually an unmasked token. This is expected if
- # you have just upgraded to masked tokens, but should stop
- # happening shortly after installing this gem.
- compare_with_real_token masked_token, session
-
- elsif masked_token.length == AUTHENTICITY_TOKEN_LENGTH * 2
- csrf_token = unmask_token(masked_token)
-
- compare_with_global_token(csrf_token, session) ||
- compare_with_real_token(csrf_token, session) ||
- valid_per_form_csrf_token?(csrf_token, session)
- else
- false # Token is malformed.
- end
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 389
+ def valid_per_form_csrf_token?(token, session) # :doc:
+ if per_form_csrf_tokens
+ correct_token = per_form_csrf_token(
+ session,
+ normalize_action_path(request.fullpath),
+ request.request_method
+ )
+
+ ActiveSupport::SecurityUtils.fixed_length_secure_compare(token, correct_token)
+ else
+ false
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 389
-def valid_per_form_csrf_token?(token, session) # :doc:
- if per_form_csrf_tokens
- correct_token = per_form_csrf_token(
- session,
- normalize_action_path(request.fullpath),
- request.request_method
- )
-
- ActiveSupport::SecurityUtils.fixed_length_secure_compare(token, correct_token)
- else
- false
- end
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 454
+ def valid_request_origin? # :doc:
+ if forgery_protection_origin_check
+ # We accept blank origin headers because some user agents don't send it.
+ raise InvalidAuthenticityToken, NULL_ORIGIN_MESSAGE if request.origin == "null"
+ request.origin.nil? || request.origin == request.base_url
+ else
+ true
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 454
-def valid_request_origin? # :doc:
- if forgery_protection_origin_check
- # We accept blank origin headers because some user agents don't send it.
- raise InvalidAuthenticityToken, NULL_ORIGIN_MESSAGE if request.origin == "null"
- request.origin.nil? || request.origin == request.base_url
- else
- true
- end
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 293
+ def verified_request? # :doc:
+ !protect_against_forgery? || request.get? || request.head? ||
+ (valid_request_origin? && any_authenticity_token_valid?)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 293
-def verified_request? # :doc:
- !protect_against_forgery? || request.get? || request.head? ||
- (valid_request_origin? && any_authenticity_token_valid?)
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 231
+ def verify_authenticity_token # :doc:
+ mark_for_same_origin_verification!
+
+ if !verified_request?
+ if logger && log_warning_on_csrf_failure
+ if valid_request_origin?
+ logger.warn "Can't verify CSRF token authenticity."
+ else
+ logger.warn "HTTP Origin header (#{request.origin}) didn't match request.base_url (#{request.base_url})"
+ end
+ end
+ handle_unverified_request
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 231
-def verify_authenticity_token # :doc:
- mark_for_same_origin_verification!
-
- if !verified_request?
- if logger && log_warning_on_csrf_failure
- if valid_request_origin?
- logger.warn "Can't verify CSRF token authenticity."
- else
- logger.warn "HTTP Origin header (#{request.origin}) didn't match request.base_url (#{request.base_url})"
- end
- end
- handle_unverified_request
- end
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 261
+ def verify_same_origin_request # :doc:
+ if marked_for_same_origin_verification? && non_xhr_javascript_response?
+ if logger && log_warning_on_csrf_failure
+ logger.warn CROSS_ORIGIN_JAVASCRIPT_WARNING
+ end
+ raise ActionController::InvalidCrossOriginRequest, CROSS_ORIGIN_JAVASCRIPT_WARNING
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 261
-def verify_same_origin_request # :doc:
- if marked_for_same_origin_verification? && non_xhr_javascript_response?
- if logger && log_warning_on_csrf_failure
- logger.warn CROSS_ORIGIN_JAVASCRIPT_WARNING
- end
- raise ActionController::InvalidCrossOriginRequest, CROSS_ORIGIN_JAVASCRIPT_WARNING
- end
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 427
+ def xor_byte_strings(s1, s2) # :doc:
+ s2_bytes = s2.bytes
+ s1.each_byte.with_index { |c1, i| s2_bytes[i] ^= c1 }
+ s2_bytes.pack("C*")
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 427
-def xor_byte_strings(s1, s2) # :doc:
- s2_bytes = s2.bytes
- s1.each_byte.with_index { |c1, i| s2_bytes[i] ^= c1 }
- s2_bytes.pack("C*")
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 133
+ def protect_from_forgery(options = {})
+ options = options.reverse_merge(prepend: false)
+
+ self.forgery_protection_strategy = protection_method_class(options[:with] || :null_session)
+ self.request_forgery_protection_token ||= :authenticity_token
+ before_action :verify_authenticity_token, options
+ append_after_action :verify_same_origin_request
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 133
-def protect_from_forgery(options = {})
- options = options.reverse_merge(prepend: false)
-
- self.forgery_protection_strategy = protection_method_class(options[:with] || :null_session)
- self.request_forgery_protection_token ||= :authenticity_token
- before_action :verify_authenticity_token, options
- append_after_action :verify_same_origin_request
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 147
+ def skip_forgery_protection(options = {})
+ skip_before_action :verify_authenticity_token, options
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 147
-def skip_forgery_protection(options = {})
- skip_before_action :verify_authenticity_token, options
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 210
+ def initialize(controller)
+ @controller = controller
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 210
-def initialize(controller)
- @controller = controller
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 214
+ def handle_unverified_request
+ raise ActionController::InvalidAuthenticityToken
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 214
-def handle_unverified_request
- raise ActionController::InvalidAuthenticityToken
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 162
+ def initialize(controller)
+ @controller = controller
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 162
-def initialize(controller)
- @controller = controller
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 167
+ def handle_unverified_request
+ request = @controller.request
+ request.session = NullSessionHash.new(request)
+ request.flash = nil
+ request.session_options = { skip: true }
+ request.cookie_jar = NullCookieJar.build(request, {})
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 167
-def handle_unverified_request
- request = @controller.request
- request.session = NullSessionHash.new(request)
- request.flash = nil
- request.session_options = { skip: true }
- request.cookie_jar = NullCookieJar.build(request, {})
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 200
+ def initialize(controller)
+ @controller = controller
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 200
-def initialize(controller)
- @controller = controller
-end
- # File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 204
+ def handle_unverified_request
+ @controller.reset_session
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 204
-def handle_unverified_request
- @controller.reset_session
-end
- # File actionpack/lib/action_controller/metal/rescue.rb, line 16
+ def show_detailed_exceptions?
+ false
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/rescue.rb, line 16
-def show_detailed_exceptions?
- false
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 1077
+ def params
+ @_params ||= Parameters.new(request.parameters)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 1077
-def params
- @_params ||= Parameters.new(request.parameters)
-end
- # File actionpack/lib/action_controller/metal/strong_parameters.rb, line 1084
+ def params=(value)
+ @_params = value.is_a?(Hash) ? Parameters.new(value) : value
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 1084
-def params=(value)
- @_params = value.is_a?(Hash) ? Parameters.new(value) : value
-end
- # File actionpack/lib/action_controller/template_assertions.rb, line 5
+ def assert_template(options = {}, message = nil)
+ raise NoMethodError,
+ "assert_template has been extracted to a gem. To continue using it,
+ add `gem 'rails-controller-testing'` to your Gemfile."
+ end
- - Source: - -
-# File actionpack/lib/action_controller/template_assertions.rb, line 5
-def assert_template(options = {}, message = nil)
- raise NoMethodError,
- "assert_template has been extracted to a gem. To continue using it,
- add `gem 'rails-controller-testing'` to your Gemfile."
-end
- # File actionpack/lib/action_controller/test_case.rb, line 588
+ def build_response(klass)
+ klass.create
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 588
-def build_response(klass)
- klass.create
-end
- # File actionpack/lib/action_controller/test_case.rb, line 548
+ def controller_class_name
+ @controller.class.anonymous? ? "anonymous" : @controller.class.controller_path
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 548
-def controller_class_name
- @controller.class.anonymous? ? "anonymous" : @controller.class.controller_path
-end
- # File actionpack/lib/action_controller/test_case.rb, line 420
+ def delete(action, **args)
+ process(action, method: "DELETE", **args)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 420
-def delete(action, **args)
- process(action, method: "DELETE", **args)
-end
- # File actionpack/lib/action_controller/test_case.rb, line 552
+ def generated_path(generated_extras)
+ generated_extras[0]
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 552
-def generated_path(generated_extras)
- generated_extras[0]
-end
- # File actionpack/lib/action_controller/test_case.rb, line 394
+ def get(action, **args)
+ res = process(action, method: "GET", **args)
+ cookies.update res.cookies
+ res
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 394
-def get(action, **args)
- res = process(action, method: "GET", **args)
- cookies.update res.cookies
- res
-end
- # File actionpack/lib/action_controller/test_case.rb, line 426
+ def head(action, **args)
+ process(action, method: "HEAD", **args)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 426
-def head(action, **args)
- process(action, method: "HEAD", **args)
-end
- # File actionpack/lib/action_controller/test_case.rb, line 408
+ def patch(action, **args)
+ process(action, method: "PATCH", **args)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 408
-def patch(action, **args)
- process(action, method: "PATCH", **args)
-end
- # File actionpack/lib/action_controller/test_case.rb, line 402
+ def post(action, **args)
+ process(action, method: "POST", **args)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 402
-def post(action, **args)
- process(action, method: "POST", **args)
-end
- # File actionpack/lib/action_controller/test_case.rb, line 460
+ def process(action, method: "GET", params: nil, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil)
+ check_required_ivars
+
+ action = action.to_s.dup
+ http_method = method.to_s.upcase
+
+ @html_document = nil
+
+ cookies.update(@request.cookies)
+ cookies.update_cookies_from_jar
+ @request.set_header "HTTP_COOKIE", cookies.to_header
+ @request.delete_header "action_dispatch.cookies"
+
+ @request = TestRequest.new scrub_env!(@request.env), @request.session, @controller.class
+ @response = build_response @response_klass
+ @response.request = @request
+ @controller.recycle!
+
+ if body
+ @request.set_header "RAW_POST_DATA", body
+ end
+
+ @request.set_header "REQUEST_METHOD", http_method
+
+ if as
+ @request.content_type = Mime[as].to_s
+ format ||= as
+ end
+
+ parameters = (params || {}).symbolize_keys
+
+ if format
+ parameters[:format] = format
+ end
+
+ generated_extras = @routes.generate_extras(parameters.merge(controller: controller_class_name, action: action))
+ generated_path = generated_path(generated_extras)
+ query_string_keys = query_parameter_names(generated_extras)
+
+ @request.assign_parameters(@routes, controller_class_name, action, parameters, generated_path, query_string_keys)
+
+ @request.session.update(session) if session
+ @request.flash.update(flash || {})
+
+ if xhr
+ @request.set_header "HTTP_X_REQUESTED_WITH", "XMLHttpRequest"
+ @request.fetch_header("HTTP_ACCEPT") do |k|
+ @request.set_header k, [Mime[:js], Mime[:html], Mime[:xml], "text/xml", "*/*"].join(", ")
+ end
+ end
+
+ @request.fetch_header("SCRIPT_NAME") do |k|
+ @request.set_header k, @controller.config.relative_url_root
+ end
+
+ begin
+ @controller.recycle!
+ @controller.dispatch(action, @request, @response)
+ ensure
+ @request = @controller.request
+ @response = @controller.response
+
+ if @request.have_cookie_jar?
+ unless @request.cookie_jar.committed?
+ @request.cookie_jar.write(@response)
+ cookies.update(@request.cookie_jar.instance_variable_get(:@cookies))
+ end
+ end
+ @response.prepare!
+
+ if flash_value = @request.flash.to_session_value
+ @request.session["flash"] = flash_value
+ else
+ @request.session.delete("flash")
+ end
+
+ if xhr
+ @request.delete_header "HTTP_X_REQUESTED_WITH"
+ @request.delete_header "HTTP_ACCEPT"
+ end
+ @request.query_string = ""
+
+ @response.sent!
+ end
+
+ @response
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 460
-def process(action, method: "GET", params: nil, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil)
- check_required_ivars
-
- action = action.to_s.dup
- http_method = method.to_s.upcase
-
- @html_document = nil
-
- cookies.update(@request.cookies)
- cookies.update_cookies_from_jar
- @request.set_header "HTTP_COOKIE", cookies.to_header
- @request.delete_header "action_dispatch.cookies"
-
- @request = TestRequest.new scrub_env!(@request.env), @request.session, @controller.class
- @response = build_response @response_klass
- @response.request = @request
- @controller.recycle!
-
- if body
- @request.set_header "RAW_POST_DATA", body
- end
-
- @request.set_header "REQUEST_METHOD", http_method
-
- if as
- @request.content_type = Mime[as].to_s
- format ||= as
- end
-
- parameters = (params || {}).symbolize_keys
-
- if format
- parameters[:format] = format
- end
-
- generated_extras = @routes.generate_extras(parameters.merge(controller: controller_class_name, action: action))
- generated_path = generated_path(generated_extras)
- query_string_keys = query_parameter_names(generated_extras)
-
- @request.assign_parameters(@routes, controller_class_name, action, parameters, generated_path, query_string_keys)
-
- @request.session.update(session) if session
- @request.flash.update(flash || {})
-
- if xhr
- @request.set_header "HTTP_X_REQUESTED_WITH", "XMLHttpRequest"
- @request.fetch_header("HTTP_ACCEPT") do |k|
- @request.set_header k, [Mime[:js], Mime[:html], Mime[:xml], "text/xml", "*/*"].join(", ")
- end
- end
-
- @request.fetch_header("SCRIPT_NAME") do |k|
- @request.set_header k, @controller.config.relative_url_root
- end
-
- begin
- @controller.recycle!
- @controller.dispatch(action, @request, @response)
- ensure
- @request = @controller.request
- @response = @controller.response
-
- if @request.have_cookie_jar?
- unless @request.cookie_jar.committed?
- @request.cookie_jar.write(@response)
- cookies.update(@request.cookie_jar.instance_variable_get(:@cookies))
- end
- end
- @response.prepare!
-
- if flash_value = @request.flash.to_session_value
- @request.session["flash"] = flash_value
- else
- @request.session.delete("flash")
- end
-
- if xhr
- @request.delete_header "HTTP_X_REQUESTED_WITH"
- @request.delete_header "HTTP_ACCEPT"
- end
- @request.query_string = ""
-
- @response.sent!
- end
-
- @response
-end
- # File actionpack/lib/action_controller/test_case.rb, line 414
+ def put(action, **args)
+ process(action, method: "PUT", **args)
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 414
-def put(action, **args)
- process(action, method: "PUT", **args)
-end
- # File actionpack/lib/action_controller/test_case.rb, line 556
+ def query_parameter_names(generated_extras)
+ generated_extras[1] + [:controller, :action]
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 556
-def query_parameter_names(generated_extras)
- generated_extras[1] + [:controller, :action]
-end
- # File actionpack/lib/action_controller/test_case.rb, line 560
+ def setup_controller_request_and_response
+ @controller = nil unless defined? @controller
+
+ @response_klass = ActionDispatch::TestResponse
+
+ if klass = self.class.controller_class
+ if klass < ActionController::Live
+ @response_klass = LiveTestResponse
+ end
+ unless @controller
+ begin
+ @controller = klass.new
+ rescue
+ warn "could not construct controller #{klass}" if $VERBOSE
+ end
+ end
+ end
+
+ @request = TestRequest.create(@controller.class)
+ @response = build_response @response_klass
+ @response.request = @request
+
+ if @controller
+ @controller.request = @request
+ @controller.params = {}
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 560
-def setup_controller_request_and_response
- @controller = nil unless defined? @controller
-
- @response_klass = ActionDispatch::TestResponse
-
- if klass = self.class.controller_class
- if klass < ActionController::Live
- @response_klass = LiveTestResponse
- end
- unless @controller
- begin
- @controller = klass.new
- rescue
- warn "could not construct controller #{klass}" if $VERBOSE
- end
- end
- end
-
- @request = TestRequest.create(@controller.class)
- @response = build_response @response_klass
- @response.request = @request
-
- if @controller
- @controller.request = @request
- @controller.params = {}
- end
-end
- # File actionpack/lib/action_controller/test_case.rb, line 359
+ def controller_class
+ if current_controller_class = _controller_class
+ current_controller_class
+ else
+ self.controller_class = determine_default_controller_class(name)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 359
-def controller_class
- if current_controller_class = _controller_class
- current_controller_class
- else
- self.controller_class = determine_default_controller_class(name)
- end
-end
- # File actionpack/lib/action_controller/test_case.rb, line 355
+ def controller_class=(new_class)
+ self._controller_class = new_class
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 355
-def controller_class=(new_class)
- self._controller_class = new_class
-end
- # File actionpack/lib/action_controller/test_case.rb, line 367
+ def determine_default_controller_class(name)
+ determine_constant_from_test_name(name) do |constant|
+ Class === constant && constant < ActionController::Metal
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 367
-def determine_default_controller_class(name)
- determine_constant_from_test_name(name) do |constant|
- Class === constant && constant < ActionController::Metal
- end
-end
- # File actionpack/lib/action_controller/test_case.rb, line 344
+ def tests(controller_class)
+ case controller_class
+ when String, Symbol
+ self.controller_class = "#{controller_class.to_s.camelize}Controller".constantize
+ when Class
+ self.controller_class = controller_class
+ else
+ raise ArgumentError, "controller class must be a String, Symbol, or Class"
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/test_case.rb, line 344
-def tests(controller_class)
- case controller_class
- when String, Symbol
- self.controller_class = "#{controller_class.to_s.camelize}Controller".constantize
- when Class
- self.controller_class = controller_class
- else
- raise ArgumentError, "controller class must be a String, Symbol, or Class"
- end
-end
- # File actionpack/lib/action_controller/metal/url_for.rb, line 30
+ def url_options
+ @_url_options ||= {
+ host: request.host,
+ port: request.optional_port,
+ protocol: request.protocol,
+ _recall: request.path_parameters
+ }.merge!(super).freeze
+
+ if (same_origin = _routes.equal?(request.routes)) ||
+ (script_name = request.engine_script_name(_routes)) ||
+ (original_script_name = request.original_script_name)
+
+ options = @_url_options.dup
+ if original_script_name
+ options[:original_script_name] = original_script_name
+ else
+ if same_origin
+ options[:script_name] = request.script_name.empty? ? "".freeze : request.script_name.dup
+ else
+ options[:script_name] = script_name
+ end
+ end
+ options.freeze
+ else
+ @_url_options
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_controller/metal/url_for.rb, line 30
-def url_options
- @_url_options ||= {
- host: request.host,
- port: request.optional_port,
- protocol: request.protocol,
- _recall: request.path_parameters
- }.merge!(super).freeze
-
- if (same_origin = _routes.equal?(request.routes)) ||
- (script_name = request.engine_script_name(_routes)) ||
- (original_script_name = request.original_script_name)
-
- options = @_url_options.dup
- if original_script_name
- options[:original_script_name] = original_script_name
- else
- if same_origin
- options[:script_name] = request.script_name.empty? ? "".freeze : request.script_name.dup
- else
- options[:script_name] = script_name
- end
- end
- options.freeze
- else
- @_url_options
- end
-end
- # File actionpack/lib/action_dispatch/testing/assertion_response.rb, line 20
+ def initialize(code_or_name)
+ if code_or_name.is_a?(Symbol)
+ @name = code_or_name
+ @code = code_from_name(code_or_name)
+ else
+ @name = name_from_code(code_or_name)
+ @code = code_or_name
+ end
+
+ raise ArgumentError, "Invalid response name: #{name}" if @code.nil?
+ raise ArgumentError, "Invalid response code: #{code}" if @name.nil?
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/assertion_response.rb, line 20
-def initialize(code_or_name)
- if code_or_name.is_a?(Symbol)
- @name = code_or_name
- @code = code_from_name(code_or_name)
- else
- @name = name_from_code(code_or_name)
- @code = code_or_name
- end
-
- raise ArgumentError, "Invalid response name: #{name}" if @code.nil?
- raise ArgumentError, "Invalid response code: #{code}" if @name.nil?
-end
- # File actionpack/lib/action_dispatch/testing/assertion_response.rb, line 33
+ def code_and_name
+ "#{code}: #{name}"
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/assertion_response.rb, line 33
-def code_and_name
- "#{code}: #{name}"
-end
- # File actionpack/lib/action_dispatch/testing/assertions.rb, line 16
+ def html_document
+ @html_document ||= if @response.content_type.to_s.end_with?("xml")
+ Nokogiri::XML::Document.parse(@response.body)
+ else
+ Nokogiri::HTML::Document.parse(@response.body)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/assertions.rb, line 16
-def html_document
- @html_document ||= if @response.content_type.to_s.end_with?("xml")
- Nokogiri::XML::Document.parse(@response.body)
- else
- Nokogiri::HTML::Document.parse(@response.body)
- end
-end
- # File actionpack/lib/action_dispatch/testing/assertions/response.rb, line 55
+ def assert_redirected_to(options = {}, message = nil)
+ assert_response(:redirect, message)
+ return true if options === @response.location
+
+ redirect_is = normalize_argument_to_redirection(@response.location)
+ redirect_expected = normalize_argument_to_redirection(options)
+
+ message ||= "Expected response to be a redirect to <#{redirect_expected}> but was a redirect to <#{redirect_is}>"
+ assert_operator redirect_expected, :===, redirect_is, message
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/assertions/response.rb, line 55
-def assert_redirected_to(options = {}, message = nil)
- assert_response(:redirect, message)
- return true if options === @response.location
-
- redirect_is = normalize_argument_to_redirection(@response.location)
- redirect_expected = normalize_argument_to_redirection(options)
-
- message ||= "Expected response to be a redirect to <#{redirect_expected}> but was a redirect to <#{redirect_is}>"
- assert_operator redirect_expected, :===, redirect_is, message
-end
- # File actionpack/lib/action_dispatch/testing/assertions/response.rb, line 30
+ def assert_response(type, message = nil)
+ message ||= generate_response_message(type)
+
+ if RESPONSE_PREDICATES.keys.include?(type)
+ assert @response.send(RESPONSE_PREDICATES[type]), message
+ else
+ assert_equal AssertionResponse.new(type).code, @response.response_code, message
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/assertions/response.rb, line 30
-def assert_response(type, message = nil)
- message ||= generate_response_message(type)
-
- if RESPONSE_PREDICATES.keys.include?(type)
- assert @response.send(RESPONSE_PREDICATES[type]), message
- else
- assert_equal AssertionResponse.new(type).code, @response.response_code, message
- end
-end
- # File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 80
+ def assert_generates(expected_path, options, defaults = {}, extras = {}, message = nil)
+ if expected_path =~ %r{://}
+ fail_on(URI::InvalidURIError, message) do
+ uri = URI.parse(expected_path)
+ expected_path = uri.path.to_s.empty? ? "/" : uri.path
+ end
+ else
+ expected_path = "/#{expected_path}" unless expected_path.first == "/"
+ end
+ # Load routes.rb if it hasn't been loaded.
+
+ options = options.clone
+ generated_path, query_string_keys = @routes.generate_extras(options, defaults)
+ found_extras = options.reject { |k, _| ! query_string_keys.include? k }
+
+ msg = message || sprintf("found extras <%s>, not <%s>", found_extras, extras)
+ assert_equal(extras, found_extras, msg)
+
+ msg = message || sprintf("The generated path <%s> did not match <%s>", generated_path,
+ expected_path)
+ assert_equal(expected_path, generated_path, msg)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 80
-def assert_generates(expected_path, options, defaults = {}, extras = {}, message = nil)
- if expected_path =~ %r{://}
- fail_on(URI::InvalidURIError, message) do
- uri = URI.parse(expected_path)
- expected_path = uri.path.to_s.empty? ? "/" : uri.path
- end
- else
- expected_path = "/#{expected_path}" unless expected_path.first == "/"
- end
- # Load routes.rb if it hasn't been loaded.
-
- options = options.clone
- generated_path, query_string_keys = @routes.generate_extras(options, defaults)
- found_extras = options.reject { |k, _| ! query_string_keys.include? k }
-
- msg = message || sprintf("found extras <%s>, not <%s>", found_extras, extras)
- assert_equal(extras, found_extras, msg)
-
- msg = message || sprintf("The generated path <%s> did not match <%s>", generated_path,
- expected_path)
- assert_equal(expected_path, generated_path, msg)
-end
- # File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 42
+ def assert_recognizes(expected_options, path, extras = {}, msg = nil)
+ if path.is_a?(Hash) && path[:method].to_s == "all"
+ [:get, :post, :put, :delete].each do |method|
+ assert_recognizes(expected_options, path.merge(method: method), extras, msg)
+ end
+ else
+ request = recognized_request_for(path, extras, msg)
+
+ expected_options = expected_options.clone
+
+ expected_options.stringify_keys!
+
+ msg = message(msg, "") {
+ sprintf("The recognized options <%s> did not match <%s>, difference:",
+ request.path_parameters, expected_options)
+ }
+
+ assert_equal(expected_options, request.path_parameters, msg)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 42
-def assert_recognizes(expected_options, path, extras = {}, msg = nil)
- if path.is_a?(Hash) && path[:method].to_s == "all"
- [:get, :post, :put, :delete].each do |method|
- assert_recognizes(expected_options, path.merge(method: method), extras, msg)
- end
- else
- request = recognized_request_for(path, extras, msg)
-
- expected_options = expected_options.clone
-
- expected_options.stringify_keys!
-
- msg = message(msg, "") {
- sprintf("The recognized options <%s> did not match <%s>, difference:",
- request.path_parameters, expected_options)
- }
-
- assert_equal(expected_options, request.path_parameters, msg)
- end
-end
- # File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 124
+ def assert_routing(path, options, defaults = {}, extras = {}, message = nil)
+ assert_recognizes(options, path, extras, message)
+
+ controller, default_controller = options[:controller], defaults[:controller]
+ if controller && controller.include?(?/) && default_controller && default_controller.include?(?/)
+ options[:controller] = "/#{controller}"
+ end
+
+ generate_options = options.dup.delete_if { |k, _| defaults.key?(k) }
+ assert_generates(path.is_a?(Hash) ? path[:path] : path, generate_options, defaults, extras, message)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 124
-def assert_routing(path, options, defaults = {}, extras = {}, message = nil)
- assert_recognizes(options, path, extras, message)
-
- controller, default_controller = options[:controller], defaults[:controller]
- if controller && controller.include?(?/) && default_controller && default_controller.include?(?/)
- options[:controller] = "/#{controller}"
- end
-
- generate_options = options.dup.delete_if { |k, _| defaults.key?(k) }
- assert_generates(path.is_a?(Hash) ? path[:path] : path, generate_options, defaults, extras, message)
-end
- # File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 172
+ def method_missing(selector, *args, &block)
+ if defined?(@controller) && @controller && defined?(@routes) && @routes && @routes.named_routes.route_defined?(selector)
+ @controller.send(selector, *args, &block)
+ else
+ super
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 172
-def method_missing(selector, *args, &block)
- if defined?(@controller) && @controller && defined?(@routes) && @routes && @routes.named_routes.route_defined?(selector)
- @controller.send(selector, *args, &block)
- else
- super
- end
-end
- # File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 149
+ def with_routing
+ old_routes, @routes = @routes, ActionDispatch::Routing::RouteSet.new
+ if defined?(@controller) && @controller
+ old_controller, @controller = @controller, @controller.clone
+ _routes = @routes
+
+ @controller.singleton_class.include(_routes.url_helpers)
+
+ if @controller.respond_to? :view_context_class
+ @controller.view_context_class = Class.new(@controller.view_context_class) do
+ include _routes.url_helpers
+ end
+ end
+ end
+ yield @routes
+ ensure
+ @routes = old_routes
+ if defined?(@controller) && @controller
+ @controller = old_controller
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 149
-def with_routing
- old_routes, @routes = @routes, ActionDispatch::Routing::RouteSet.new
- if defined?(@controller) && @controller
- old_controller, @controller = @controller, @controller.clone
- _routes = @routes
-
- @controller.singleton_class.include(_routes.url_helpers)
-
- if @controller.respond_to? :view_context_class
- @controller.view_context_class = Class.new(@controller.view_context_class) do
- include _routes.url_helpers
- end
- end
- end
- yield @routes
-ensure
- @routes = old_routes
- if defined?(@controller) && @controller
- @controller = old_controller
- end
-end
- # File actionpack/lib/action_dispatch/middleware/callbacks.rb, line 15
+ def after(*args, &block)
+ set_callback(:call, :after, *args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/callbacks.rb, line 15
-def after(*args, &block)
- set_callback(:call, :after, *args, &block)
-end
- # File actionpack/lib/action_dispatch/middleware/callbacks.rb, line 11
+ def before(*args, &block)
+ set_callback(:call, :before, *args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/callbacks.rb, line 11
-def before(*args, &block)
- set_callback(:call, :before, *args, &block)
-end
- # File actionpack/lib/action_dispatch/middleware/callbacks.rb, line 20
+ def initialize(app)
+ @app = app
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/callbacks.rb, line 20
-def initialize(app)
- @app = app
-end
- # File actionpack/lib/action_dispatch/middleware/callbacks.rb, line 24
+ def call(env)
+ error = nil
+ result = run_callbacks :call do
+ begin
+ @app.call(env)
+ rescue => error
+ end
+ end
+ raise error if error
+ result
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/callbacks.rb, line 24
-def call(env)
- error = nil
- result = run_callbacks :call do
- begin
- @app.call(env)
- rescue => error
- end
- end
- raise error if error
- result
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 133
+ def initialize
+ @directives = {}
+ yield self if block_given?
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 133
-def initialize
- @directives = {}
- yield self if block_given?
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 152
+ def block_all_mixed_content(enabled = true)
+ if enabled
+ @directives["block-all-mixed-content"] = true
+ else
+ @directives.delete("block-all-mixed-content")
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 152
-def block_all_mixed_content(enabled = true)
- if enabled
- @directives["block-all-mixed-content"] = true
- else
- @directives.delete("block-all-mixed-content")
- end
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 198
+ def build(context = nil, nonce = nil)
+ build_directives(context, nonce).compact.join("; ")
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 198
-def build(context = nil, nonce = nil)
- build_directives(context, nonce).compact.join("; ")
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 138
+ def initialize_copy(other)
+ @directives = other.directives.deep_dup
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 138
-def initialize_copy(other)
- @directives = other.directives.deep_dup
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 160
+ def plugin_types(*types)
+ if types.first
+ @directives["plugin-types"] = types
+ else
+ @directives.delete("plugin-types")
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 160
-def plugin_types(*types)
- if types.first
- @directives["plugin-types"] = types
- else
- @directives.delete("plugin-types")
- end
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 168
+ def report_uri(uri)
+ @directives["report-uri"] = [uri]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 168
-def report_uri(uri)
- @directives["report-uri"] = [uri]
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 172
+ def require_sri_for(*types)
+ if types.first
+ @directives["require-sri-for"] = types
+ else
+ @directives.delete("require-sri-for")
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 172
-def require_sri_for(*types)
- if types.first
- @directives["require-sri-for"] = types
- else
- @directives.delete("require-sri-for")
- end
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 180
+ def sandbox(*values)
+ if values.empty?
+ @directives["sandbox"] = true
+ elsif values.first
+ @directives["sandbox"] = values
+ else
+ @directives.delete("sandbox")
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 180
-def sandbox(*values)
- if values.empty?
- @directives["sandbox"] = true
- elsif values.first
- @directives["sandbox"] = values
- else
- @directives.delete("sandbox")
- end
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 190
+ def upgrade_insecure_requests(enabled = true)
+ if enabled
+ @directives["upgrade-insecure-requests"] = true
+ else
+ @directives.delete("upgrade-insecure-requests")
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 190
-def upgrade_insecure_requests(enabled = true)
- if enabled
- @directives["upgrade-insecure-requests"] = true
- else
- @directives.delete("upgrade-insecure-requests")
- end
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 12
+ def initialize(app)
+ @app = app
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 12
-def initialize(app)
- @app = app
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 16
+ def call(env)
+ request = ActionDispatch::Request.new env
+ _, headers, _ = response = @app.call(env)
+
+ return response if policy_present?(headers)
+
+ if policy = request.content_security_policy
+ nonce = request.content_security_policy_nonce
+ context = request.controller_instance || request
+ headers[header_name(request)] = policy.build(context, nonce)
+ end
+
+ response
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 16
-def call(env)
- request = ActionDispatch::Request.new env
- _, headers, _ = response = @app.call(env)
-
- return response if policy_present?(headers)
-
- if policy = request.content_security_policy
- nonce = request.content_security_policy_nonce
- context = request.controller_instance || request
- headers[header_name(request)] = policy.build(context, nonce)
- end
-
- response
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 51
+ def content_security_policy
+ get_header(POLICY)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 51
-def content_security_policy
- get_header(POLICY)
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 55
+ def content_security_policy=(policy)
+ set_header(POLICY, policy)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 55
-def content_security_policy=(policy)
- set_header(POLICY, policy)
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 75
+ def content_security_policy_nonce
+ if content_security_policy_nonce_generator
+ if nonce = get_header(NONCE)
+ nonce
+ else
+ set_header(NONCE, generate_content_security_policy_nonce)
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 75
-def content_security_policy_nonce
- if content_security_policy_nonce_generator
- if nonce = get_header(NONCE)
- nonce
- else
- set_header(NONCE, generate_content_security_policy_nonce)
- end
- end
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 67
+ def content_security_policy_nonce_generator
+ get_header(NONCE_GENERATOR)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 67
-def content_security_policy_nonce_generator
- get_header(NONCE_GENERATOR)
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 71
+ def content_security_policy_nonce_generator=(generator)
+ set_header(NONCE_GENERATOR, generator)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 71
-def content_security_policy_nonce_generator=(generator)
- set_header(NONCE_GENERATOR, generator)
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 59
+ def content_security_policy_report_only
+ get_header(POLICY_REPORT_ONLY)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 59
-def content_security_policy_report_only
- get_header(POLICY_REPORT_ONLY)
-end
- # File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 63
+ def content_security_policy_report_only=(value)
+ set_header(POLICY_REPORT_ONLY, value)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/content_security_policy.rb, line 63
-def content_security_policy_report_only=(value)
- set_header(POLICY_REPORT_ONLY, value)
-end
- # File actionpack/lib/action_dispatch/middleware/cookies.rb, line 663
+ def initialize(app)
+ @app = app
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/cookies.rb, line 663
-def initialize(app)
- @app = app
-end
- # File actionpack/lib/action_dispatch/middleware/cookies.rb, line 667
+ def call(env)
+ request = ActionDispatch::Request.new env
+
+ status, headers, body = @app.call(env)
+
+ if request.have_cookie_jar?
+ cookie_jar = request.cookie_jar
+ unless cookie_jar.committed?
+ cookie_jar.write(headers)
+ if headers[HTTP_HEADER].respond_to?(:join)
+ headers[HTTP_HEADER] = headers[HTTP_HEADER].join("\n")
+ end
+ end
+ end
+
+ [status, headers, body]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/cookies.rb, line 667
-def call(env)
- request = ActionDispatch::Request.new env
-
- status, headers, body = @app.call(env)
-
- if request.have_cookie_jar?
- cookie_jar = request.cookie_jar
- unless cookie_jar.committed?
- cookie_jar.write(headers)
- if headers[HTTP_HEADER].respond_to?(:join)
- headers[HTTP_HEADER] = headers[HTTP_HEADER].join("\n")
- end
- end
- end
-
- [status, headers, body]
-end
- # File actionpack/lib/action_dispatch/middleware/cookies.rb, line 245
+ def encrypted
+ @encrypted ||= EncryptedKeyRotatingCookieJar.new(self)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/cookies.rb, line 245
-def encrypted
- @encrypted ||= EncryptedKeyRotatingCookieJar.new(self)
-end
- # File actionpack/lib/action_dispatch/middleware/cookies.rb, line 205
+ def permanent
+ @permanent ||= PermanentCookieJar.new(self)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/cookies.rb, line 205
-def permanent
- @permanent ||= PermanentCookieJar.new(self)
-end
- # File actionpack/lib/action_dispatch/middleware/cookies.rb, line 224
+ def signed
+ @signed ||= SignedKeyRotatingCookieJar.new(self)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/cookies.rb, line 224
-def signed
- @signed ||= SignedKeyRotatingCookieJar.new(self)
-end
- # File actionpack/lib/action_dispatch/middleware/cookies.rb, line 251
+ def signed_or_encrypted
+ @signed_or_encrypted ||=
+ if request.secret_key_base.present?
+ encrypted
+ else
+ signed
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/cookies.rb, line 251
-def signed_or_encrypted
- @signed_or_encrypted ||=
- if request.secret_key_base.present?
- encrypted
- else
- signed
- end
-end
- # File actionpack/lib/action_dispatch/middleware/debug_exceptions.rb, line 53
+ def initialize(app, routes_app = nil, response_format = :default)
+ @app = app
+ @routes_app = routes_app
+ @response_format = response_format
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/debug_exceptions.rb, line 53
-def initialize(app, routes_app = nil, response_format = :default)
- @app = app
- @routes_app = routes_app
- @response_format = response_format
-end
- # File actionpack/lib/action_dispatch/middleware/debug_exceptions.rb, line 59
+ def call(env)
+ request = ActionDispatch::Request.new env
+ _, headers, body = response = @app.call(env)
+
+ if headers["X-Cascade"] == "pass"
+ body.close if body.respond_to?(:close)
+ raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
+ end
+
+ response
+ rescue Exception => exception
+ raise exception unless request.show_exceptions?
+ render_exception(request, exception)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/debug_exceptions.rb, line 59
-def call(env)
- request = ActionDispatch::Request.new env
- _, headers, body = response = @app.call(env)
-
- if headers["X-Cascade"] == "pass"
- body.close if body.respond_to?(:close)
- raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
- end
-
- response
-rescue Exception => exception
- raise exception unless request.show_exceptions?
- render_exception(request, exception)
-end
- # File actionpack/lib/action_dispatch/middleware/debug_locks.rb, line 26
+ def initialize(app, path = "/rails/locks")
+ @app = app
+ @path = path
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/debug_locks.rb, line 26
-def initialize(app, path = "/rails/locks")
- @app = app
- @path = path
-end
- # File actionpack/lib/action_dispatch/middleware/debug_locks.rb, line 31
+ def call(env)
+ req = ActionDispatch::Request.new env
+
+ if req.get?
+ path = req.path_info.chomp("/".freeze)
+ if path == @path
+ return render_details(req)
+ end
+ end
+
+ @app.call(env)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/debug_locks.rb, line 31
-def call(env)
- req = ActionDispatch::Request.new env
-
- if req.get?
- path = req.path_info.chomp("/".freeze)
- if path == @path
- return render_details(req)
- end
- end
-
- @app.call(env)
-end
- # File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 34
+ def initialize(backtrace_cleaner, exception)
+ @backtrace_cleaner = backtrace_cleaner
+ @exception = original_exception(exception)
+
+ expand_backtrace if exception.is_a?(SyntaxError) || exception.cause.is_a?(SyntaxError)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 34
-def initialize(backtrace_cleaner, exception)
- @backtrace_cleaner = backtrace_cleaner
- @exception = original_exception(exception)
-
- expand_backtrace if exception.is_a?(SyntaxError) || exception.cause.is_a?(SyntaxError)
-end
- # File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 85
+ def self.status_code_for_exception(class_name)
+ Rack::Utils.status_code(@@rescue_responses[class_name])
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 85
-def self.status_code_for_exception(class_name)
- Rack::Utils.status_code(@@rescue_responses[class_name])
-end
- # File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 49
+ def application_trace
+ clean_backtrace(:silent)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 49
-def application_trace
- clean_backtrace(:silent)
-end
- # File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 53
+ def framework_trace
+ clean_backtrace(:noise)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 53
-def framework_trace
- clean_backtrace(:noise)
-end
- # File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 57
+ def full_trace
+ clean_backtrace(:all)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 57
-def full_trace
- clean_backtrace(:all)
-end
- # File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 41
+ def rescue_template
+ @@rescue_templates[@exception.class.name]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 41
-def rescue_template
- @@rescue_templates[@exception.class.name]
-end
- # File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 89
+ def source_extracts
+ backtrace.map do |trace|
+ file, line_number = extract_file_and_line_number(trace)
+
+ {
+ code: source_fragment(file, line_number),
+ line_number: line_number
+ }
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 89
-def source_extracts
- backtrace.map do |trace|
- file, line_number = extract_file_and_line_number(trace)
-
- {
- code: source_fragment(file, line_number),
- line_number: line_number
- }
- end
-end
- # File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 45
+ def status_code
+ self.class.status_code_for_exception(@exception.class.name)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 45
-def status_code
- self.class.status_code_for_exception(@exception.class.name)
-end
- # File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 61
+ def traces
+ application_trace_with_ids = []
+ framework_trace_with_ids = []
+ full_trace_with_ids = []
+
+ full_trace.each_with_index do |trace, idx|
+ trace_with_id = { id: idx, trace: trace }
+
+ if application_trace.include?(trace)
+ application_trace_with_ids << trace_with_id
+ else
+ framework_trace_with_ids << trace_with_id
+ end
+
+ full_trace_with_ids << trace_with_id
+ end
+
+ {
+ "Application Trace" => application_trace_with_ids,
+ "Framework Trace" => framework_trace_with_ids,
+ "Full Trace" => full_trace_with_ids
+ }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/exception_wrapper.rb, line 61
-def traces
- application_trace_with_ids = []
- framework_trace_with_ids = []
- full_trace_with_ids = []
-
- full_trace.each_with_index do |trace, idx|
- trace_with_id = { id: idx, trace: trace }
-
- if application_trace.include?(trace)
- application_trace_with_ids << trace_with_id
- else
- framework_trace_with_ids << trace_with_id
- end
-
- full_trace_with_ids << trace_with_id
- end
-
- {
- "Application Trace" => application_trace_with_ids,
- "Framework Trace" => framework_trace_with_ids,
- "Full Trace" => full_trace_with_ids
- }
-end
- # File actionpack/lib/action_dispatch/middleware/executor.rb, line 7
+ def initialize(app, executor)
+ @app, @executor = app, executor
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/executor.rb, line 7
-def initialize(app, executor)
- @app, @executor = app, executor
-end
- # File actionpack/lib/action_dispatch/middleware/executor.rb, line 11
+ def call(env)
+ state = @executor.run!(reset: true)
+ begin
+ response = @app.call(env)
+ returned = response << ::Rack::BodyProxy.new(response.pop) { state.complete! }
+ ensure
+ state.complete! unless returned
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/executor.rb, line 11
-def call(env)
- state = @executor.run!(reset: true)
- begin
- response = @app.call(env)
- returned = response << ::Rack::BodyProxy.new(response.pop) { state.complete! }
- ensure
- state.complete! unless returned
- end
-end
- # File actionpack/lib/action_dispatch/middleware/static.rb, line 18
+ def initialize(root, index: "index", headers: {})
+ @root = root.chomp("/").b
+ @file_server = ::Rack::File.new(@root, headers)
+ @index = index
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/static.rb, line 18
-def initialize(root, index: "index", headers: {})
- @root = root.chomp("/").b
- @file_server = ::Rack::File.new(@root, headers)
- @index = index
-end
- # File actionpack/lib/action_dispatch/middleware/static.rb, line 50
+ def call(env)
+ serve(Rack::Request.new(env))
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/static.rb, line 50
-def call(env)
- serve(Rack::Request.new(env))
-end
- # File actionpack/lib/action_dispatch/middleware/static.rb, line 30
+ def match?(path)
+ path = ::Rack::Utils.unescape_path path
+ return false unless ::Rack::Utils.valid_path? path
+ path = ::Rack::Utils.clean_path_info path
+
+ paths = [path, "#{path}#{ext}", "#{path}/#{@index}#{ext}"]
+
+ if match = paths.detect { |p|
+ path = File.join(@root, p.b)
+ begin
+ File.file?(path) && File.readable?(path)
+ rescue SystemCallError
+ false
+ end
+
+ }
+ return ::Rack::Utils.escape_path(match).b
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/static.rb, line 30
-def match?(path)
- path = ::Rack::Utils.unescape_path path
- return false unless ::Rack::Utils.valid_path? path
- path = ::Rack::Utils.clean_path_info path
-
- paths = [path, "#{path}#{ext}", "#{path}/#{@index}#{ext}"]
-
- if match = paths.detect { |p|
- path = File.join(@root, p.b)
- begin
- File.file?(path) && File.readable?(path)
- rescue SystemCallError
- false
- end
-
- }
- return ::Rack::Utils.escape_path(match).b
- end
-end
- # File actionpack/lib/action_dispatch/middleware/static.rb, line 54
+ def serve(request)
+ path = request.path_info
+ gzip_path = gzip_file_path(path)
+
+ if gzip_path && gzip_encoding_accepted?(request)
+ request.path_info = gzip_path
+ status, headers, body = @file_server.call(request.env)
+ if status == 304
+ return [status, headers, body]
+ end
+ headers["Content-Encoding"] = "gzip"
+ headers["Content-Type"] = content_type(path)
+ else
+ status, headers, body = @file_server.call(request.env)
+ end
+
+ headers["Vary"] = "Accept-Encoding" if gzip_path
+
+ return [status, headers, body]
+ ensure
+ request.path_info = path
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/static.rb, line 54
-def serve(request)
- path = request.path_info
- gzip_path = gzip_file_path(path)
-
- if gzip_path && gzip_encoding_accepted?(request)
- request.path_info = gzip_path
- status, headers, body = @file_server.call(request.env)
- if status == 304
- return [status, headers, body]
- end
- headers["Content-Encoding"] = "gzip"
- headers["Content-Type"] = content_type(path)
- else
- status, headers, body = @file_server.call(request.env)
- end
-
- headers["Vary"] = "Accept-Encoding" if gzip_path
-
- return [status, headers, body]
-ensure
- request.path_info = path
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 294
+ def self.new(app) app; end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 294
-def self.new(app) app; end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 161
-def [](k)
- @flashes[k.to_s]
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 161
+ def [](k)
+ @flashes[k.to_s]
+ end
+
+ 🔎 See on GitHub
+
+ # File actionpack/lib/action_dispatch/middleware/flash.rb, line 155
+ def []=(k, v)
+ k = k.to_s
+ @discard.delete k
+ @flashes[k] = v
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 155
-def []=(k, v)
- k = k.to_s
- @discard.delete k
- @flashes[k] = v
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 262
+ def alert
+ self[:alert]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 262
-def alert
- self[:alert]
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 267
+ def alert=(message)
+ self[:alert] = message
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 267
-def alert=(message)
- self[:alert] = message
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 194
+ def clear
+ @discard.clear
+ @flashes.clear
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 194
-def clear
- @discard.clear
- @flashes.clear
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 179
+ def delete(key)
+ key = key.to_s
+ @discard.delete key
+ @flashes.delete key
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 179
-def delete(key)
- key = key.to_s
- @discard.delete key
- @flashes.delete key
- self
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 247
+ def discard(k = nil)
+ k = k.to_s if k
+ @discard.merge Array(k || keys)
+ k ? self[k] : self
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 247
-def discard(k = nil)
- k = k.to_s if k
- @discard.merge Array(k || keys)
- k ? self[k] : self
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 199
+ def each(&block)
+ @flashes.each(&block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 199
-def each(&block)
- @flashes.each(&block)
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 190
+ def empty?
+ @flashes.empty?
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 190
-def empty?
- @flashes.empty?
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 147
+ def initialize_copy(other)
+ if other.now_is_loaded?
+ @now = other.now.dup
+ @now.flash = self
+ end
+ super
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 147
-def initialize_copy(other)
- if other.now_is_loaded?
- @now = other.now.dup
- @now.flash = self
- end
- super
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 237
+ def keep(k = nil)
+ k = k.to_s if k
+ @discard.subtract Array(k || keys)
+ k ? self[k] : self
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 237
-def keep(k = nil)
- k = k.to_s if k
- @discard.subtract Array(k || keys)
- k ? self[k] : self
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 175
+ def key?(name)
+ @flashes.key? name.to_s
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 175
-def key?(name)
- @flashes.key? name.to_s
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 171
+ def keys
+ @flashes.keys
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 171
-def keys
- @flashes.keys
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 272
+ def notice
+ self[:notice]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 272
-def notice
- self[:notice]
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 277
+ def notice=(message)
+ self[:notice] = message
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 277
-def notice=(message)
- self[:notice] = message
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 229
+ def now
+ @now ||= FlashNow.new(self)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 229
-def now
- @now ||= FlashNow.new(self)
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 186
+ def to_hash
+ @flashes.dup
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 186
-def to_hash
- @flashes.dup
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 282
+ def now_is_loaded?
+ @now
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 282
-def now_is_loaded?
- @now
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 287
+ def stringify_array(array) # :doc:
+ array.map do |item|
+ item.kind_of?(Symbol) ? item.to_s : item
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 287
-def stringify_array(array) # :doc:
- array.map do |item|
- item.kind_of?(Symbol) ? item.to_s : item
- end
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 47
+ def flash
+ flash = flash_hash
+ return flash if flash
+ self.flash = Flash::FlashHash.from_session_value(session["flash"])
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 47
-def flash
- flash = flash_hash
- return flash if flash
- self.flash = Flash::FlashHash.from_session_value(session["flash"])
-end
- # File actionpack/lib/action_dispatch/middleware/flash.rb, line 53
+ def flash=(flash)
+ set_header Flash::KEY, flash
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/flash.rb, line 53
-def flash=(flash)
- set_header Flash::KEY, flash
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 28
+ def etag_matches?(etag)
+ if etag
+ validators = if_none_match_etags
+ validators.include?(etag) || validators.include?("*")
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 28
-def etag_matches?(etag)
- if etag
- validators = if_none_match_etags
- validators.include?(etag) || validators.include?("*")
- end
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 38
+ def fresh?(response)
+ last_modified = if_modified_since
+ etag = if_none_match
+
+ return false unless last_modified || etag
+
+ success = true
+ success &&= not_modified?(response.last_modified) if last_modified
+ success &&= etag_matches?(response.etag) if etag
+ success
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 38
-def fresh?(response)
- last_modified = if_modified_since
- etag = if_none_match
-
- return false unless last_modified || etag
-
- success = true
- success &&= not_modified?(response.last_modified) if last_modified
- success &&= etag_matches?(response.etag) if etag
- success
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 10
+ def if_modified_since
+ if since = get_header(HTTP_IF_MODIFIED_SINCE)
+ Time.rfc2822(since) rescue nil
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 10
-def if_modified_since
- if since = get_header(HTTP_IF_MODIFIED_SINCE)
- Time.rfc2822(since) rescue nil
- end
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 16
+ def if_none_match
+ get_header HTTP_IF_NONE_MATCH
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 16
-def if_none_match
- get_header HTTP_IF_NONE_MATCH
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 20
+ def if_none_match_etags
+ if_none_match ? if_none_match.split(/\s*,\s*/) : []
+ end
- - Source: - -
- -# File actionpack/lib/action_dispatch/http/cache.rb, line 24
+ def not_modified?(modified_at)
+ if_modified_since && modified_at && if_modified_since >= modified_at
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 24
-def not_modified?(modified_at)
- if_modified_since && modified_at && if_modified_since >= modified_at
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 68
-def date
- if date_header = get_header(DATE)
- Time.httpdate(date_header)
- end
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 68
+ def date
+ if date_header = get_header(DATE)
+ Time.httpdate(date_header)
+ end
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 78
-def date=(utc_time)
- set_header DATE, utc_time.httpdate
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 78
+ def date=(utc_time)
+ set_header DATE, utc_time.httpdate
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 74
-def date?
- has_header? DATE
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 74
+ def date?
+ has_header? DATE
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 101
-def etag=(weak_validators)
- self.weak_etag = weak_validators
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 101
+ def etag=(weak_validators)
+ self.weak_etag = weak_validators
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 113
-def etag?; etag; end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 113
+ def etag?; etag; end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 54
-def last_modified
- if last = get_header(LAST_MODIFIED)
- Time.httpdate(last)
- end
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 54
+ def last_modified
+ if last = get_header(LAST_MODIFIED)
+ Time.httpdate(last)
+ end
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 64
-def last_modified=(utc_time)
- set_header LAST_MODIFIED, utc_time.httpdate
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 64
+ def last_modified=(utc_time)
+ set_header LAST_MODIFIED, utc_time.httpdate
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 60
-def last_modified?
- has_header? LAST_MODIFIED
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 60
+ def last_modified?
+ has_header? LAST_MODIFIED
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 109
-def strong_etag=(strong_validators)
- set_header "ETag", generate_strong_etag(strong_validators)
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 109
+ def strong_etag=(strong_validators)
+ set_header "ETag", generate_strong_etag(strong_validators)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 121
-def strong_etag?
- etag? && !weak_etag?
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 121
+ def strong_etag?
+ etag? && !weak_etag?
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 105
-def weak_etag=(weak_validators)
- set_header "ETag", generate_weak_etag(weak_validators)
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 105
+ def weak_etag=(weak_validators)
+ set_header "ETag", generate_weak_etag(weak_validators)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/cache.rb, line 116
-def weak_etag?
- etag? && etag.starts_with?('W/"')
-end
- # File actionpack/lib/action_dispatch/http/cache.rb, line 116
+ def weak_etag?
+ etag? && etag.starts_with?('W/"')
+ end
+
+ 🔎 See on GitHub
+
+ # File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 34
+ def initialize
+ super
+ @filtered_parameters = nil
+ @filtered_env = nil
+ @filtered_path = nil
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 34
-def initialize
- super
- @filtered_parameters = nil
- @filtered_env = nil
- @filtered_path = nil
-end
- # File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 47
+ def filtered_env
+ @filtered_env ||= env_filter.filter(@env)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 47
-def filtered_env
- @filtered_env ||= env_filter.filter(@env)
-end
- # File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 42
+ def filtered_parameters
+ @filtered_parameters ||= parameter_filter.filter(parameters)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 42
-def filtered_parameters
- @filtered_parameters ||= parameter_filter.filter(parameters)
-end
- # File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 52
+ def filtered_path
+ @filtered_path ||= query_string.empty? ? path : "#{path}?#{filtered_query_string}"
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 52
-def filtered_path
- @filtered_path ||= query_string.empty? ? path : "#{path}?#{filtered_query_string}"
-end
- # File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 64
+ def env_filter # :doc:
+ user_key = fetch_header("action_dispatch.parameter_filter") {
+ return NULL_ENV_FILTER
+ }
+ parameter_filter_for(Array(user_key) + ENV_MATCH)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 64
-def env_filter # :doc:
- user_key = fetch_header("action_dispatch.parameter_filter") {
- return NULL_ENV_FILTER
- }
- parameter_filter_for(Array(user_key) + ENV_MATCH)
-end
- # File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 77
+ def filtered_query_string # :doc:
+ query_string.gsub(PAIR_RE) do |_|
+ parameter_filter.filter($1 => $2).first.join("=")
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 77
-def filtered_query_string # :doc:
- query_string.gsub(PAIR_RE) do |_|
- parameter_filter.filter($1 => $2).first.join("=")
- end
-end
- # File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 58
+ def parameter_filter # :doc:
+ parameter_filter_for fetch_header("action_dispatch.parameter_filter") {
+ return NULL_PARAM_FILTER
+ }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 58
-def parameter_filter # :doc:
- parameter_filter_for fetch_header("action_dispatch.parameter_filter") {
- return NULL_PARAM_FILTER
- }
-end
- # File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 71
+ def parameter_filter_for(filters) # :doc:
+ ParameterFilter.new(filters)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 71
-def parameter_filter_for(filters) # :doc:
- ParameterFilter.new(filters)
-end
- # File actionpack/lib/action_dispatch/http/headers.rb, line 50
+ def self.from_hash(hash)
+ new ActionDispatch::Request.new hash
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/headers.rb, line 50
-def self.from_hash(hash)
- new ActionDispatch::Request.new hash
-end
- # File actionpack/lib/action_dispatch/http/headers.rb, line 59
+ def [](key)
+ @req.get_header env_name(key)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/headers.rb, line 59
-def [](key)
- @req.get_header env_name(key)
-end
- # File actionpack/lib/action_dispatch/http/headers.rb, line 64
+ def []=(key, value)
+ @req.set_header env_name(key), value
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/headers.rb, line 64
-def []=(key, value)
- @req.set_header env_name(key), value
-end
- # File actionpack/lib/action_dispatch/http/headers.rb, line 69
+ def add(key, value)
+ @req.add_header env_name(key), value
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/headers.rb, line 69
-def add(key, value)
- @req.add_header env_name(key), value
-end
- # File actionpack/lib/action_dispatch/http/headers.rb, line 95
+ def each(&block)
+ @req.each_header(&block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/headers.rb, line 95
-def each(&block)
- @req.each_header(&block)
-end
- # File actionpack/lib/action_dispatch/http/headers.rb, line 116
+ def env; @req.env.dup; end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/headers.rb, line 116
-def env; @req.env.dup; end
- # File actionpack/lib/action_dispatch/http/headers.rb, line 87
+ def fetch(key, default = DEFAULT)
+ @req.fetch_header(env_name(key)) do
+ return default unless default == DEFAULT
+ return yield if block_given?
+ raise KeyError, key
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/headers.rb, line 87
-def fetch(key, default = DEFAULT)
- @req.fetch_header(env_name(key)) do
- return default unless default == DEFAULT
- return yield if block_given?
- raise KeyError, key
- end
-end
- # File actionpack/lib/action_dispatch/http/headers.rb, line 73
+ def key?(key)
+ @req.has_header? env_name(key)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/headers.rb, line 73
-def key?(key)
- @req.has_header? env_name(key)
-end
- # File actionpack/lib/action_dispatch/http/headers.rb, line 101
+ def merge(headers_or_env)
+ headers = @req.dup.headers
+ headers.merge!(headers_or_env)
+ headers
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/headers.rb, line 101
-def merge(headers_or_env)
- headers = @req.dup.headers
- headers.merge!(headers_or_env)
- headers
-end
- # File actionpack/lib/action_dispatch/http/headers.rb, line 110
+ def merge!(headers_or_env)
+ headers_or_env.each do |key, value|
+ @req.set_header env_name(key), value
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/headers.rb, line 110
-def merge!(headers_or_env)
- headers_or_env.each do |key, value|
- @req.set_header env_name(key), value
- end
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 35
-def accepts
- fetch_header("action_dispatch.request.accepts") do |k|
- header = get_header("HTTP_ACCEPT").to_s.strip
-
- v = if header.empty?
- [content_mime_type]
- else
- Mime::Type.parse(header)
- end
- set_header k, v
- end
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 35
+ def accepts
+ fetch_header("action_dispatch.request.accepts") do |k|
+ header = get_header("HTTP_ACCEPT").to_s.strip
+
+ v = if header.empty?
+ [content_mime_type]
+ else
+ Mime::Type.parse(header)
+ end
+ set_header k, v
+ end
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 15
-def content_mime_type
- fetch_header("action_dispatch.request.content_type") do |k|
- v = if get_header("CONTENT_TYPE") =~ /^([^,\;]*)/
- Mime::Type.lookup($1.strip.downcase)
- else
- nil
- end
- set_header k, v
- end
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 15
+ def content_mime_type
+ fetch_header("action_dispatch.request.content_type") do |k|
+ v = if get_header("CONTENT_TYPE") =~ /^([^,\;]*)/
+ Mime::Type.lookup($1.strip.downcase)
+ else
+ nil
+ end
+ set_header k, v
+ end
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 26
-def content_type
- content_mime_type && content_mime_type.to_s
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 26
+ def content_type
+ content_mime_type && content_mime_type.to_s
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 54
-def format(view_path = [])
- formats.first || Mime::NullType.instance
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 54
+ def format(view_path = [])
+ formats.first || Mime::NullType.instance
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 115
-def format=(extension)
- parameters[:format] = extension.to_s
- set_header "action_dispatch.request.formats", [Mime::Type.lookup_by_extension(parameters[:format])]
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 115
+ def format=(extension)
+ parameters[:format] = extension.to_s
+ set_header "action_dispatch.request.formats", [Mime::Type.lookup_by_extension(parameters[:format])]
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 58
-def formats
- fetch_header("action_dispatch.request.formats") do |k|
- params_readable = begin
- parameters[:format]
- rescue ActionController::BadRequest
- false
- end
-
- v = if params_readable
- Array(Mime[parameters[:format]])
- elsif use_accept_header && valid_accept_header
- accepts
- elsif extension_format = format_from_path_extension
- [extension_format]
- elsif xhr?
- [Mime[:js]]
- else
- [Mime[:html]]
- end
-
- v = v.select do |format|
- format.symbol || format.ref == "*/*"
- end
-
- set_header k, v
- end
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 58
+ def formats
+ fetch_header("action_dispatch.request.formats") do |k|
+ params_readable = begin
+ parameters[:format]
+ rescue ActionController::BadRequest
+ false
+ end
+
+ v = if params_readable
+ Array(Mime[parameters[:format]])
+ elsif use_accept_header && valid_accept_header
+ accepts
+ elsif extension_format = format_from_path_extension
+ [extension_format]
+ elsif xhr?
+ [Mime[:js]]
+ else
+ [Mime[:html]]
+ end
+
+ v = v.select do |format|
+ format.symbol || format.ref == "*/*"
+ end
+
+ set_header k, v
+ end
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 134
-def formats=(extensions)
- parameters[:format] = extensions.first.to_s
- set_header "action_dispatch.request.formats", extensions.collect { |extension|
- Mime::Type.lookup_by_extension(extension)
- }
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 134
+ def formats=(extensions)
+ parameters[:format] = extensions.first.to_s
+ set_header "action_dispatch.request.formats", extensions.collect { |extension|
+ Mime::Type.lookup_by_extension(extension)
+ }
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 142
-def negotiate_mime(order)
- formats.each do |priority|
- if priority == Mime::ALL
- return order.first
- elsif order.include?(priority)
- return priority
- end
- end
-
- order.include?(Mime::ALL) ? format : nil
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 142
+ def negotiate_mime(order)
+ formats.each do |priority|
+ if priority == Mime::ALL
+ return order.first
+ elsif order.include?(priority)
+ return priority
+ end
+ end
+
+ order.include?(Mime::ALL) ? format : nil
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 100
-def variant
- @variant ||= ActiveSupport::ArrayInquirer.new
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 100
+ def variant
+ @variant ||= ActiveSupport::ArrayInquirer.new
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 87
-def variant=(variant)
- variant = Array(variant)
-
- if variant.all? { |v| v.is_a?(Symbol) }
- @variant = ActiveSupport::ArrayInquirer.new(variant)
- else
- raise ArgumentError, "request.variant must be set to a Symbol or an Array of Symbols. " \
- "For security reasons, never directly set the variant to a user-provided value, " \
- "like params[:variant].to_sym. Check user-provided value against a whitelist first, " \
- "then set the variant: request.variant = :tablet if params[:variant] == 'tablet'"
- end
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 87
+ def variant=(variant)
+ variant = Array(variant)
+
+ if variant.all? { |v| v.is_a?(Symbol) }
+ @variant = ActiveSupport::ArrayInquirer.new(variant)
+ else
+ raise ArgumentError, "request.variant must be set to a Symbol or an Array of Symbols. " \
+ "For security reasons, never directly set the variant to a user-provided value, " \
+ "like params[:variant].to_sym. Check user-provided value against a whitelist first, " \
+ "then set the variant: request.variant = :tablet if params[:variant] == 'tablet'"
+ end
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 167
-def format_from_path_extension # :doc:
- path = get_header("action_dispatch.original_path") || get_header("PATH_INFO")
- if match = path && path.match(/\.(\w+)\z/)
- Mime[match.captures.first]
- end
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 167
+ def format_from_path_extension # :doc:
+ path = get_header("action_dispatch.original_path") || get_header("PATH_INFO")
+ if match = path && path.match(/\.(\w+)\z/)
+ Mime[match.captures.first]
+ end
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 163
-def use_accept_header # :doc:
- !self.class.ignore_accept_header
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 163
+ def use_accept_header # :doc:
+ !self.class.ignore_accept_header
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 158
-def valid_accept_header # :doc:
- (xhr? && (accept.present? || content_mime_type)) ||
- (accept.present? && accept !~ BROWSER_LIKE_ACCEPTS)
-end
- # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 158
+ def valid_accept_header # :doc:
+ (xhr? && (accept.present? || content_mime_type)) ||
+ (accept.present? && accept !~ BROWSER_LIKE_ACCEPTS)
+ end
+
+ 🔎 See on GitHub
+
+ # File actionpack/lib/action_dispatch/http/parameter_filter.rb, line 10
+ def initialize(filters = [])
+ @filters = filters
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/parameter_filter.rb, line 10
-def initialize(filters = [])
- @filters = filters
-end
- # File actionpack/lib/action_dispatch/http/parameter_filter.rb, line 14
+ def filter(params)
+ compiled_filter.call(params)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/parameter_filter.rb, line 14
-def filter(params)
- compiled_filter.call(params)
-end
- # File actionpack/lib/action_dispatch/http/parameters.rb, line 50
+ def parameters
+ params = get_header("action_dispatch.request.parameters")
+ return params if params
+
+ params = begin
+ request_parameters.merge(query_parameters)
+ rescue EOFError
+ query_parameters.dup
+ end
+ params.merge!(path_parameters)
+ params = set_binary_encoding(params, params[:controller], params[:action])
+ set_header("action_dispatch.request.parameters", params)
+ params
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/parameters.rb, line 50
-def parameters
- params = get_header("action_dispatch.request.parameters")
- return params if params
-
- params = begin
- request_parameters.merge(query_parameters)
- rescue EOFError
- query_parameters.dup
- end
- params.merge!(path_parameters)
- params = set_binary_encoding(params, params[:controller], params[:action])
- set_header("action_dispatch.request.parameters", params)
- params
-end
- # File actionpack/lib/action_dispatch/http/parameters.rb, line 83
+ def path_parameters
+ get_header(PARAMETERS_KEY) || set_header(PARAMETERS_KEY, {})
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/parameters.rb, line 83
-def path_parameters
- get_header(PARAMETERS_KEY) || set_header(PARAMETERS_KEY, {})
-end
- # File actionpack/lib/action_dispatch/http/parameters.rb, line 44
+ def parameter_parsers=(parsers)
+ @parameter_parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/parameters.rb, line 44
-def parameter_parsers=(parsers)
- @parameter_parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key }
-end
- # File actionpack/lib/action_dispatch/http/parameters.rb, line 20
+ def initialize
+ super($!.message)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/parameters.rb, line 20
-def initialize
- super($!.message)
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 21
+ def extract_domain(host, tld_length)
+ extract_domain_from(host, tld_length) if named_host?(host)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 21
-def extract_domain(host, tld_length)
- extract_domain_from(host, tld_length) if named_host?(host)
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 45
+ def extract_subdomain(host, tld_length)
+ extract_subdomains(host, tld_length).join(".")
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 45
-def extract_subdomain(host, tld_length)
- extract_subdomains(host, tld_length).join(".")
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 31
+ def extract_subdomains(host, tld_length)
+ if named_host?(host)
+ extract_subdomains_from(host, tld_length)
+ else
+ []
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 31
-def extract_subdomains(host, tld_length)
- if named_host?(host)
- extract_subdomains_from(host, tld_length)
- else
- []
- end
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 57
+ def full_url_for(options)
+ host = options[:host]
+ protocol = options[:protocol]
+ port = options[:port]
+
+ unless host
+ raise ArgumentError, "Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true"
+ end
+
+ build_host_url(host, port, protocol, options, path_for(options))
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 57
-def full_url_for(options)
- host = options[:host]
- protocol = options[:protocol]
- port = options[:port]
-
- unless host
- raise ArgumentError, "Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true"
- end
-
- build_host_url(host, port, protocol, options, path_for(options))
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 186
+ def initialize
+ super
+ @protocol = nil
+ @port = nil
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 186
-def initialize
- super
- @protocol = nil
- @port = nil
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 69
+ def path_for(options)
+ path = options[:script_name].to_s.chomp("/".freeze)
+ path << options[:path] if options.key?(:path)
+
+ add_trailing_slash(path) if options[:trailing_slash]
+ add_params(path, options[:params]) if options.key?(:params)
+ add_anchor(path, options[:anchor]) if options.key?(:anchor)
+
+ path
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 69
-def path_for(options)
- path = options[:script_name].to_s.chomp("/".freeze)
- path << options[:path] if options.key?(:path)
-
- add_trailing_slash(path) if options[:trailing_slash]
- add_params(path, options[:params]) if options.key?(:params)
- add_anchor(path, options[:anchor]) if options.key?(:anchor)
-
- path
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 49
+ def url_for(options)
+ if options[:only_path]
+ path_for options
+ else
+ full_url_for options
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 49
-def url_for(options)
- if options[:only_path]
- path_for options
- else
- full_url_for options
- end
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 329
+ def domain(tld_length = @@tld_length)
+ ActionDispatch::Http::URL.extract_domain(host, tld_length)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 329
-def domain(tld_length = @@tld_length)
- ActionDispatch::Http::URL.extract_domain(host, tld_length)
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 233
+ def host
+ raw_host_with_port.sub(/:\d+$/, "".freeze)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 233
-def host
- raw_host_with_port.sub(/:\d+$/, "".freeze)
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 249
+ def host_with_port
+ "#{host}#{port_string}"
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 249
-def host_with_port
- "#{host}#{port_string}"
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 300
+ def optional_port
+ standard_port? ? nil : port
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 300
-def optional_port
- standard_port? ? nil : port
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 260
+ def port
+ @port ||= begin
+ if raw_host_with_port =~ /:(\d+)$/
+ $1.to_i
+ else
+ standard_port
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 260
-def port
- @port ||= begin
- if raw_host_with_port =~ /:(\d+)$/
- $1.to_i
- else
- standard_port
- end
- end
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 312
+ def port_string
+ standard_port? ? "" : ":#{port}"
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 312
-def port_string
- standard_port? ? "" : ":#{port}"
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 207
+ def protocol
+ @protocol ||= ssl? ? "https://" : "http://"
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 207
-def protocol
- @protocol ||= ssl? ? "https://" : "http://"
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 221
+ def raw_host_with_port
+ if forwarded = x_forwarded_host.presence
+ forwarded.split(/,\s?/).last
+ else
+ get_header("HTTP_HOST") || "#{server_name || server_addr}:#{get_header('SERVER_PORT')}"
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 221
-def raw_host_with_port
- if forwarded = x_forwarded_host.presence
- forwarded.split(/,\s?/).last
- else
- get_header("HTTP_HOST") || "#{server_name || server_addr}:#{get_header('SERVER_PORT')}"
- end
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 323
+ def server_port
+ get_header("SERVER_PORT").to_i
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 323
-def server_port
- get_header("SERVER_PORT").to_i
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 274
+ def standard_port
+ case protocol
+ when "https://" then 443
+ else 80
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 274
-def standard_port
- case protocol
- when "https://" then 443
- else 80
- end
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 288
+ def standard_port?
+ port == standard_port
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 288
-def standard_port?
- port == standard_port
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 345
+ def subdomain(tld_length = @@tld_length)
+ ActionDispatch::Http::URL.extract_subdomain(host, tld_length)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 345
-def subdomain(tld_length = @@tld_length)
- ActionDispatch::Http::URL.extract_subdomain(host, tld_length)
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 337
+ def subdomains(tld_length = @@tld_length)
+ ActionDispatch::Http::URL.extract_subdomains(host, tld_length)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 337
-def subdomains(tld_length = @@tld_length)
- ActionDispatch::Http::URL.extract_subdomains(host, tld_length)
-end
- # File actionpack/lib/action_dispatch/http/url.rb, line 196
+ def url
+ protocol + host_with_port + fullpath
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/url.rb, line 196
-def url
- protocol + host_with_port + fullpath
-end
- # File actionpack/lib/action_dispatch/http/upload.rb, line 59
+ def close(unlink_now = false)
+ @tempfile.close(unlink_now)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/upload.rb, line 59
-def close(unlink_now = false)
- @tempfile.close(unlink_now)
-end
- # File actionpack/lib/action_dispatch/http/upload.rb, line 79
+ def eof?
+ @tempfile.eof?
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/upload.rb, line 79
-def eof?
- @tempfile.eof?
-end
- # File actionpack/lib/action_dispatch/http/upload.rb, line 54
+ def open
+ @tempfile.open
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/upload.rb, line 54
-def open
- @tempfile.open
-end
- # File actionpack/lib/action_dispatch/http/upload.rb, line 64
+ def path
+ @tempfile.path
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/upload.rb, line 64
-def path
- @tempfile.path
-end
- # File actionpack/lib/action_dispatch/http/upload.rb, line 49
+ def read(length = nil, buffer = nil)
+ @tempfile.read(length, buffer)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/upload.rb, line 49
-def read(length = nil, buffer = nil)
- @tempfile.read(length, buffer)
-end
- # File actionpack/lib/action_dispatch/http/upload.rb, line 69
+ def rewind
+ @tempfile.rewind
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/upload.rb, line 69
-def rewind
- @tempfile.rewind
-end
- # File actionpack/lib/action_dispatch/http/upload.rb, line 74
+ def size
+ @tempfile.size
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/upload.rb, line 74
-def size
- @tempfile.size
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 41
+ def delete(path, **args)
+ process(:delete, path, **args)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 41
-def delete(path, **args)
- process(:delete, path, **args)
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 54
+ def follow_redirect!
+ raise "not a redirect! #{status} #{status_message}" unless redirect?
+ get(response.location)
+ status
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 54
-def follow_redirect!
- raise "not a redirect! #{status} #{status_message}" unless redirect?
- get(response.location)
- status
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 17
+ def get(path, **args)
+ process(:get, path, **args)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 17
-def get(path, **args)
- process(:get, path, **args)
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 47
+ def head(path, *args)
+ process(:head, path, *args)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 47
-def head(path, *args)
- process(:head, path, *args)
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 29
+ def patch(path, **args)
+ process(:patch, path, **args)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 29
-def patch(path, **args)
- process(:patch, path, **args)
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 23
+ def post(path, **args)
+ process(:post, path, **args)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 23
-def post(path, **args)
- process(:post, path, **args)
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 35
+ def put(path, **args)
+ process(:put, path, **args)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 35
-def put(path, **args)
- process(:put, path, **args)
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 307
+ def initialize(*args, &blk)
+ super(*args, &blk)
+ @integration_session = nil
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 307
-def initialize(*args, &blk)
- super(*args, &blk)
- @integration_session = nil
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 327
+ def create_session(app)
+ klass = APP_SESSIONS[app] ||= Class.new(Integration::Session) {
+ # If the app is a Rails app, make url_helpers available on the session.
+ # This makes app.url_for and app.foo_path available in the console.
+ if app.respond_to?(:routes)
+ include app.routes.url_helpers
+ include app.routes.mounted_helpers
+ end
+ }
+ klass.new(app)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 327
-def create_session(app)
- klass = APP_SESSIONS[app] ||= Class.new(Integration::Session) {
- # If the app is a Rails app, make url_helpers available on the session.
- # This makes app.url_for and app.foo_path available in the console.
- if app.respond_to?(:routes)
- include app.routes.url_helpers
- include app.routes.mounted_helpers
- end
- }
- klass.new(app)
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 381
+ def default_url_options
+ integration_session.default_url_options
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 381
-def default_url_options
- integration_session.default_url_options
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 385
+ def default_url_options=(options)
+ integration_session.default_url_options = options
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 385
-def default_url_options=(options)
- integration_session.default_url_options = options
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 317
+ def integration_session
+ @integration_session ||= create_session(app)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 317
-def integration_session
- @integration_session ||= create_session(app)
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 366
+ def open_session
+ dup.tap do |session|
+ session.reset!
+ yield session if block_given?
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 366
-def open_session
- dup.tap do |session|
- session.reset!
- yield session if block_given?
- end
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 323
+ def reset!
+ @integration_session = create_session(app)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 323
-def reset!
- @integration_session = create_session(app)
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 116
+ def initialize(app)
+ super()
+ @app = app
+
+ reset!
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 116
-def initialize(app)
- super()
- @app = app
-
- reset!
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 97
+ def cookies
+ _mock_session.cookie_jar
+ end
- - Source: - -
- -# File actionpack/lib/action_dispatch/testing/integration.rb, line 84
+ def host
+ @host || DEFAULT_HOST
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 84
-def host
- @host || DEFAULT_HOST
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 164
+ def https!(flag = true)
+ @https = flag
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 164
-def https!(flag = true)
- @https = flag
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 173
+ def https?
+ @https
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 173
-def https?
- @https
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 204
+ def process(method, path, params: nil, headers: nil, env: nil, xhr: false, as: nil)
+ request_encoder = RequestEncoder.encoder(as)
+ headers ||= {}
+
+ if method == :get && as == :json && params
+ headers["X-Http-Method-Override"] = "GET"
+ method = :post
+ end
+
+ if path =~ %r{://}
+ path = build_expanded_path(path) do |location|
+ https! URI::HTTPS === location if location.scheme
+
+ if url_host = location.host
+ default = Rack::Request::DEFAULT_PORTS[location.scheme]
+ url_host += ":#{location.port}" if default != location.port
+ host! url_host
+ end
+ end
+ end
+
+ hostname, port = host.split(":")
+
+ request_env = {
+ :method => method,
+ :params => request_encoder.encode_params(params),
+
+ "SERVER_NAME" => hostname,
+ "SERVER_PORT" => port || (https? ? "443" : "80"),
+ "HTTPS" => https? ? "on" : "off",
+ "rack.url_scheme" => https? ? "https" : "http",
+
+ "REQUEST_URI" => path,
+ "HTTP_HOST" => host,
+ "REMOTE_ADDR" => remote_addr,
+ "CONTENT_TYPE" => request_encoder.content_type,
+ "HTTP_ACCEPT" => request_encoder.accept_header || accept
+ }
+
+ wrapped_headers = Http::Headers.from_hash({})
+ wrapped_headers.merge!(headers) if headers
+
+ if xhr
+ wrapped_headers["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
+ wrapped_headers["HTTP_ACCEPT"] ||= [Mime[:js], Mime[:html], Mime[:xml], "text/xml", "*/*"].join(", ")
+ end
+
+ # This modifies the passed request_env directly.
+ if wrapped_headers.present?
+ Http::Headers.from_hash(request_env).merge!(wrapped_headers)
+ end
+ if env.present?
+ Http::Headers.from_hash(request_env).merge!(env)
+ end
+
+ session = Rack::Test::Session.new(_mock_session)
+
+ # NOTE: rack-test v0.5 doesn't build a default uri correctly
+ # Make sure requested path is always a full URI.
+ session.request(build_full_uri(path, request_env), request_env)
+
+ @request_count += 1
+ @request = ActionDispatch::Request.new(session.last_request.env)
+ response = _mock_session.last_response
+ @response = ActionDispatch::TestResponse.from_response(response)
+ @response.request = @request
+ @html_document = nil
+ @url_options = nil
+
+ @controller = @request.controller_instance
+
+ response.status
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 204
-def process(method, path, params: nil, headers: nil, env: nil, xhr: false, as: nil)
- request_encoder = RequestEncoder.encoder(as)
- headers ||= {}
-
- if method == :get && as == :json && params
- headers["X-Http-Method-Override"] = "GET"
- method = :post
- end
-
- if path =~ %r{://}
- path = build_expanded_path(path) do |location|
- https! URI::HTTPS === location if location.scheme
-
- if url_host = location.host
- default = Rack::Request::DEFAULT_PORTS[location.scheme]
- url_host += ":#{location.port}" if default != location.port
- host! url_host
- end
- end
- end
-
- hostname, port = host.split(":")
-
- request_env = {
- :method => method,
- :params => request_encoder.encode_params(params),
-
- "SERVER_NAME" => hostname,
- "SERVER_PORT" => port || (https? ? "443" : "80"),
- "HTTPS" => https? ? "on" : "off",
- "rack.url_scheme" => https? ? "https" : "http",
-
- "REQUEST_URI" => path,
- "HTTP_HOST" => host,
- "REMOTE_ADDR" => remote_addr,
- "CONTENT_TYPE" => request_encoder.content_type,
- "HTTP_ACCEPT" => request_encoder.accept_header || accept
- }
-
- wrapped_headers = Http::Headers.from_hash({})
- wrapped_headers.merge!(headers) if headers
-
- if xhr
- wrapped_headers["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
- wrapped_headers["HTTP_ACCEPT"] ||= [Mime[:js], Mime[:html], Mime[:xml], "text/xml", "*/*"].join(", ")
- end
-
- # This modifies the passed request_env directly.
- if wrapped_headers.present?
- Http::Headers.from_hash(request_env).merge!(wrapped_headers)
- end
- if env.present?
- Http::Headers.from_hash(request_env).merge!(env)
- end
-
- session = Rack::Test::Session.new(_mock_session)
-
- # NOTE: rack-test v0.5 doesn't build a default uri correctly
- # Make sure requested path is always a full URI.
- session.request(build_full_uri(path, request_env), request_env)
-
- @request_count += 1
- @request = ActionDispatch::Request.new(session.last_request.env)
- response = _mock_session.last_response
- @response = ActionDispatch::TestResponse.from_response(response)
- @response.request = @request
- @html_document = nil
- @url_options = nil
-
- @controller = @request.controller_instance
-
- response.status
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 140
+ def reset!
+ @https = false
+ @controller = @request = @response = nil
+ @_mock_session = nil
+ @request_count = 0
+ @url_options = nil
+
+ self.host = DEFAULT_HOST
+ self.remote_addr = "127.0.0.1"
+ self.accept = "text/xml,application/xml,application/xhtml+xml," \
+ "text/html;q=0.9,text/plain;q=0.8,image/png," \
+ "*/*;q=0.5"
+
+ unless defined? @named_routes_configured
+ # the helpers are made protected by default--we make them public for
+ # easier access during testing and troubleshooting.
+ @named_routes_configured = true
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 140
-def reset!
- @https = false
- @controller = @request = @response = nil
- @_mock_session = nil
- @request_count = 0
- @url_options = nil
-
- self.host = DEFAULT_HOST
- self.remote_addr = "127.0.0.1"
- self.accept = "text/xml,application/xml,application/xhtml+xml," \
- "text/html;q=0.9,text/plain;q=0.8,image/png," \
- "*/*;q=0.5"
-
- unless defined? @named_routes_configured
- # the helpers are made protected by default--we make them public for
- # easier access during testing and troubleshooting.
- @named_routes_configured = true
- end
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 123
+ def url_options
+ @url_options ||= default_url_options.dup.tap do |url_options|
+ url_options.reverse_merge!(controller.url_options) if controller
+
+ if @app.respond_to?(:routes)
+ url_options.reverse_merge!(@app.routes.default_url_options)
+ end
+
+ url_options.reverse_merge!(host: host, protocol: https? ? "https" : "http")
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 123
-def url_options
- @url_options ||= default_url_options.dup.tap do |url_options|
- url_options.reverse_merge!(controller.url_options) if controller
-
- if @app.respond_to?(:routes)
- url_options.reverse_merge!(@app.routes.default_url_options)
- end
-
- url_options.reverse_merge!(host: host, protocol: https? ? "https" : "http")
- end
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 642
+ def app
+ super || self.class.app
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 642
-def app
- super || self.class.app
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 646
+ def document_root_element
+ html_document.root
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 646
-def document_root_element
- html_document.root
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 625
+ def app
+ if defined?(@@app) && @@app
+ @@app
+ else
+ ActionDispatch.test_app
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 625
-def app
- if defined?(@@app) && @@app
- @@app
- else
- ActionDispatch.test_app
- end
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 633
+ def app=(app)
+ @@app = app
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 633
-def app=(app)
- @@app = app
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 637
+ def register_encoder(*args)
+ RequestEncoder.register_encoder(*args)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 637
-def register_encoder(*args)
- RequestEncoder.register_encoder(*args)
-end
- # File actionpack/lib/action_dispatch/testing/integration.rb, line 606
+ def url_options
+ integration_session.url_options
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/integration.rb, line 606
-def url_options
- integration_session.url_options
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 45
-def initialize(*args)
- @middlewares = []
- yield(self) if block_given?
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 45
+ def initialize(*args)
+ @middlewares = []
+ yield(self) if block_given?
+ end
+
+ 🔎 See on GitHub
+
+ # File actionpack/lib/action_dispatch/middleware/stack.rb, line 62
+ def [](i)
+ middlewares[i]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 62
-def [](i)
- middlewares[i]
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 100
+ def build(app = nil, &block)
+ middlewares.freeze.reverse.inject(app || block) { |a, e| e.build(a) }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 100
-def build(app = nil, &block)
- middlewares.freeze.reverse.inject(app || block) { |a, e| e.build(a) }
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 92
+ def delete(target)
+ middlewares.delete_if { |m| m.klass == target }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 92
-def delete(target)
- middlewares.delete_if { |m| m.klass == target }
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 50
+ def each
+ @middlewares.each { |x| yield x }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 50
-def each
- @middlewares.each { |x| yield x }
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 70
+ def initialize_copy(other)
+ self.middlewares = other.middlewares.dup
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 70
-def initialize_copy(other)
- self.middlewares = other.middlewares.dup
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 74
+ def insert(index, klass, *args, &block)
+ index = assert_index(index, :before)
+ middlewares.insert(index, build_middleware(klass, args, block))
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 74
-def insert(index, klass, *args, &block)
- index = assert_index(index, :before)
- middlewares.insert(index, build_middleware(klass, args, block))
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 81
+ def insert_after(index, *args, &block)
+ index = assert_index(index, :after)
+ insert(index + 1, *args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 81
-def insert_after(index, *args, &block)
- index = assert_index(index, :after)
- insert(index + 1, *args, &block)
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 58
+ def last
+ middlewares.last
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 58
-def last
- middlewares.last
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 54
+ def size
+ middlewares.size
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 54
-def size
- middlewares.size
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 86
+ def swap(target, *args, &block)
+ index = assert_index(target, :before)
+ insert(index, *args, &block)
+ middlewares.delete_at(index + 1)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 86
-def swap(target, *args, &block)
- index = assert_index(target, :before)
- insert(index, *args, &block)
- middlewares.delete_at(index + 1)
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 66
+ def unshift(klass, *args, &block)
+ middlewares.unshift(build_middleware(klass, args, block))
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 66
-def unshift(klass, *args, &block)
- middlewares.unshift(build_middleware(klass, args, block))
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 96
+ def use(klass, *args, &block)
+ middlewares.push(build_middleware(klass, args, block))
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 96
-def use(klass, *args, &block)
- middlewares.push(build_middleware(klass, args, block))
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 11
+ def initialize(klass, args, block)
+ @klass = klass
+ @args = args
+ @block = block
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 11
-def initialize(klass, args, block)
- @klass = klass
- @args = args
- @block = block
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 19
+ def ==(middleware)
+ case middleware
+ when Middleware
+ klass == middleware.klass
+ when Class
+ klass == middleware
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 19
-def ==(middleware)
- case middleware
- when Middleware
- klass == middleware.klass
- when Class
- klass == middleware
- end
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 36
+ def build(app)
+ klass.new(app, *args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 36
-def build(app)
- klass.new(app, *args, &block)
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 28
+ def inspect
+ if klass.is_a?(Class)
+ klass.to_s
+ else
+ klass.class.to_s
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 28
-def inspect
- if klass.is_a?(Class)
- klass.to_s
- else
- klass.class.to_s
- end
-end
- # File actionpack/lib/action_dispatch/middleware/stack.rb, line 17
+ def name; klass.name; end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/stack.rb, line 17
-def name; klass.name; end
- # File actionpack/lib/action_dispatch/middleware/public_exceptions.rb, line 17
+ def initialize(public_path)
+ @public_path = public_path
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/public_exceptions.rb, line 17
-def initialize(public_path)
- @public_path = public_path
-end
- # File actionpack/lib/action_dispatch/middleware/public_exceptions.rb, line 21
+ def call(env)
+ request = ActionDispatch::Request.new(env)
+ status = request.path_info[1..-1].to_i
+ content_type = request.formats.first
+ body = { status: status, error: Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500]) }
+
+ render(status, content_type, body)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/public_exceptions.rb, line 21
-def call(env)
- request = ActionDispatch::Request.new(env)
- status = request.path_info[1..-1].to_i
- content_type = request.formats.first
- body = { status: status, error: Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500]) }
-
- render(status, content_type, body)
-end
- # File actionpack/lib/action_dispatch/http/rack_cache.rb, line 37
+ def initialize(store = Rails.cache)
+ @store = store
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/rack_cache.rb, line 37
-def initialize(store = Rails.cache)
- @store = store
-end
- # File actionpack/lib/action_dispatch/http/rack_cache.rb, line 33
+ def self.resolve(uri)
+ new
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/rack_cache.rb, line 33
-def self.resolve(uri)
- new
-end
- # File actionpack/lib/action_dispatch/http/rack_cache.rb, line 41
+ def exist?(key)
+ @store.exist?(key)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/rack_cache.rb, line 41
-def exist?(key)
- @store.exist?(key)
-end
- # File actionpack/lib/action_dispatch/http/rack_cache.rb, line 45
+ def open(key)
+ @store.read(key)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/rack_cache.rb, line 45
-def open(key)
- @store.read(key)
-end
- # File actionpack/lib/action_dispatch/http/rack_cache.rb, line 49
+ def read(key)
+ body = open(key)
+ body.join if body
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/rack_cache.rb, line 49
-def read(key)
- body = open(key)
- body.join if body
-end
- # File actionpack/lib/action_dispatch/http/rack_cache.rb, line 54
+ def write(body)
+ buf = []
+ key, size = slurp(body) { |part| buf << part }
+ @store.write(key, buf)
+ [key, size]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/rack_cache.rb, line 54
-def write(body)
- buf = []
- key, size = slurp(body) { |part| buf << part }
- @store.write(key, buf)
- [key, size]
-end
- # File actionpack/lib/action_dispatch/http/rack_cache.rb, line 13
+ def initialize(store = Rails.cache)
+ @store = store
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/rack_cache.rb, line 13
-def initialize(store = Rails.cache)
- @store = store
-end
- # File actionpack/lib/action_dispatch/http/rack_cache.rb, line 9
+ def self.resolve(uri)
+ new
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/rack_cache.rb, line 9
-def self.resolve(uri)
- new
-end
- # File actionpack/lib/action_dispatch/http/rack_cache.rb, line 17
+ def read(key)
+ if data = @store.read(key)
+ Marshal.load(data)
+ else
+ []
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/rack_cache.rb, line 17
-def read(key)
- if data = @store.read(key)
- Marshal.load(data)
- else
- []
- end
-end
- # File actionpack/lib/action_dispatch/http/rack_cache.rb, line 25
+ def write(key, value)
+ @store.write(key, Marshal.dump(value))
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/rack_cache.rb, line 25
-def write(key, value)
- @store.write(key, Marshal.dump(value))
-end
- # File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 62
+ def initialize(app, ip_spoofing_check = true, custom_proxies = nil)
+ @app = app
+ @check_ip = ip_spoofing_check
+ @proxies = if custom_proxies.blank?
+ TRUSTED_PROXIES
+ elsif custom_proxies.respond_to?(:any?)
+ custom_proxies
+ else
+ Array(custom_proxies) + TRUSTED_PROXIES
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 62
-def initialize(app, ip_spoofing_check = true, custom_proxies = nil)
- @app = app
- @check_ip = ip_spoofing_check
- @proxies = if custom_proxies.blank?
- TRUSTED_PROXIES
- elsif custom_proxies.respond_to?(:any?)
- custom_proxies
- else
- Array(custom_proxies) + TRUSTED_PROXIES
- end
-end
- # File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 78
+ def call(env)
+ req = ActionDispatch::Request.new env
+ req.remote_ip = GetIp.new(req, check_ip, proxies)
+ @app.call(req.env)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 78
-def call(env)
- req = ActionDispatch::Request.new env
- req.remote_ip = GetIp.new(req, check_ip, proxies)
- @app.call(req.env)
-end
- # File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 88
+ def initialize(req, check_ip, proxies)
+ @req = req
+ @check_ip = check_ip
+ @proxies = proxies
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 88
-def initialize(req, check_ip, proxies)
- @req = req
- @check_ip = check_ip
- @proxies = proxies
-end
- # File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 112
+ def calculate_ip
+ # Set by the Rack web server, this is a single value.
+ remote_addr = ips_from(@req.remote_addr).last
+
+ # Could be a CSV list and/or repeated headers that were concatenated.
+ client_ips = ips_from(@req.client_ip).reverse
+ forwarded_ips = ips_from(@req.x_forwarded_for).reverse
+
+ # +Client-Ip+ and +X-Forwarded-For+ should not, generally, both be set.
+ # If they are both set, it means that either:
+ #
+ # 1) This request passed through two proxies with incompatible IP header
+ # conventions.
+ # 2) The client passed one of +Client-Ip+ or +X-Forwarded-For+
+ # (whichever the proxy servers weren't using) themselves.
+ #
+ # Either way, there is no way for us to determine which header is the
+ # right one after the fact. Since we have no idea, if we are concerned
+ # about IP spoofing we need to give up and explode. (If you're not
+ # concerned about IP spoofing you can turn the +ip_spoofing_check+
+ # option off.)
+ should_check_ip = @check_ip && client_ips.last && forwarded_ips.last
+ if should_check_ip && !forwarded_ips.include?(client_ips.last)
+ # We don't know which came from the proxy, and which from the user
+ raise IpSpoofAttackError, "IP spoofing attack?! " \
+ "HTTP_CLIENT_IP=#{@req.client_ip.inspect} " \
+ "HTTP_X_FORWARDED_FOR=#{@req.x_forwarded_for.inspect}"
+ end
+
+ # We assume these things about the IP headers:
+ #
+ # - X-Forwarded-For will be a list of IPs, one per proxy, or blank
+ # - Client-Ip is propagated from the outermost proxy, or is blank
+ # - REMOTE_ADDR will be the IP that made the request to Rack
+ ips = [forwarded_ips, client_ips, remote_addr].flatten.compact
+
+ # If every single IP option is in the trusted list, just return REMOTE_ADDR
+ filter_proxies(ips).first || remote_addr
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 112
-def calculate_ip
- # Set by the Rack web server, this is a single value.
- remote_addr = ips_from(@req.remote_addr).last
-
- # Could be a CSV list and/or repeated headers that were concatenated.
- client_ips = ips_from(@req.client_ip).reverse
- forwarded_ips = ips_from(@req.x_forwarded_for).reverse
-
- # +Client-Ip+ and +X-Forwarded-For+ should not, generally, both be set.
- # If they are both set, it means that either:
- #
- # 1) This request passed through two proxies with incompatible IP header
- # conventions.
- # 2) The client passed one of +Client-Ip+ or +X-Forwarded-For+
- # (whichever the proxy servers weren't using) themselves.
- #
- # Either way, there is no way for us to determine which header is the
- # right one after the fact. Since we have no idea, if we are concerned
- # about IP spoofing we need to give up and explode. (If you're not
- # concerned about IP spoofing you can turn the +ip_spoofing_check+
- # option off.)
- should_check_ip = @check_ip && client_ips.last && forwarded_ips.last
- if should_check_ip && !forwarded_ips.include?(client_ips.last)
- # We don't know which came from the proxy, and which from the user
- raise IpSpoofAttackError, "IP spoofing attack?! " \
- "HTTP_CLIENT_IP=#{@req.client_ip.inspect} " \
- "HTTP_X_FORWARDED_FOR=#{@req.x_forwarded_for.inspect}"
- end
-
- # We assume these things about the IP headers:
- #
- # - X-Forwarded-For will be a list of IPs, one per proxy, or blank
- # - Client-Ip is propagated from the outermost proxy, or is blank
- # - REMOTE_ADDR will be the IP that made the request to Rack
- ips = [forwarded_ips, client_ips, remote_addr].flatten.compact
-
- # If every single IP option is in the trusted list, just return REMOTE_ADDR
- filter_proxies(ips).first || remote_addr
-end
- # File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 154
+ def to_s
+ @ip ||= calculate_ip
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 154
-def to_s
- @ip ||= calculate_ip
-end
- # File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 176
+ def filter_proxies(ips) # :doc:
+ ips.reject do |ip|
+ @proxies.any? { |proxy| proxy === ip }
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 176
-def filter_proxies(ips) # :doc:
- ips.reject do |ip|
- @proxies.any? { |proxy| proxy === ip }
- end
-end
- # File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 160
+ def ips_from(header) # :doc:
+ return [] unless header
+ # Split the comma-separated list into an array of strings.
+ ips = header.strip.split(/[,\s]+/)
+ ips.select do |ip|
+ begin
+ # Only return IPs that are valid according to the IPAddr#new method.
+ range = IPAddr.new(ip).to_range
+ # We want to make sure nobody is sneaking a netmask in.
+ range.begin == range.end
+ rescue ArgumentError
+ nil
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 160
-def ips_from(header) # :doc:
- return [] unless header
- # Split the comma-separated list into an array of strings.
- ips = header.strip.split(/[,\s]+/)
- ips.select do |ip|
- begin
- # Only return IPs that are valid according to the IPAddr#new method.
- range = IPAddr.new(ip).to_range
- # We want to make sure nobody is sneaking a netmask in.
- range.begin == range.end
- rescue ArgumentError
- nil
- end
- end
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 55
+ def self.empty
+ new({})
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 55
-def self.empty
- new({})
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 59
+ def initialize(env)
+ super
+ @method = nil
+ @request_method = nil
+ @remote_ip = nil
+ @original_fullpath = nil
+ @fullpath = nil
+ @ip = nil
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 59
-def initialize(env)
- super
- @method = nil
- @request_method = nil
- @remote_ip = nil
- @original_fullpath = nil
- @fullpath = nil
- @ip = nil
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 366
+ def GET
+ fetch_header("action_dispatch.request.query_parameters") do |k|
+ rack_query_params = super || {}
+ # Check for non UTF-8 parameter values, which would cause errors later
+ Request::Utils.check_param_encoding(rack_query_params)
+ set_header k, Request::Utils.normalize_encode_params(rack_query_params)
+ end
+ rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
+ raise ActionController::BadRequest.new("Invalid query parameters: #{e.message}")
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 366
-def GET
- fetch_header("action_dispatch.request.query_parameters") do |k|
- rack_query_params = super || {}
- # Check for non UTF-8 parameter values, which would cause errors later
- Request::Utils.check_param_encoding(rack_query_params)
- set_header k, Request::Utils.normalize_encode_params(rack_query_params)
- end
-rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
- raise ActionController::BadRequest.new("Invalid query parameters: #{e.message}")
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 379
+ def POST
+ fetch_header("action_dispatch.request.request_parameters") do
+ pr = parse_formatted_parameters(params_parsers) do |params|
+ super || {}
+ end
+ self.request_parameters = Request::Utils.normalize_encode_params(pr)
+ end
+ rescue Http::Parameters::ParseError # one of the parse strategies blew up
+ self.request_parameters = Request::Utils.normalize_encode_params(super || {})
+ raise
+ rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
+ raise ActionController::BadRequest.new("Invalid request parameters: #{e.message}")
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 379
-def POST
- fetch_header("action_dispatch.request.request_parameters") do
- pr = parse_formatted_parameters(params_parsers) do |params|
- super || {}
- end
- self.request_parameters = Request::Utils.normalize_encode_params(pr)
- end
-rescue Http::Parameters::ParseError # one of the parse strategies blew up
- self.request_parameters = Request::Utils.normalize_encode_params(super || {})
- raise
-rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
- raise ActionController::BadRequest.new("Invalid request parameters: #{e.message}")
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 396
+ def authorization
+ get_header("HTTP_AUTHORIZATION") ||
+ get_header("X-HTTP_AUTHORIZATION") ||
+ get_header("X_HTTP_AUTHORIZATION") ||
+ get_header("REDIRECT_X_HTTP_AUTHORIZATION")
+ end
- - Source: - -
- -# File actionpack/lib/action_dispatch/http/request.rb, line 322
+ def body
+ if raw_post = get_header("RAW_POST_DATA")
+ raw_post = raw_post.dup.force_encoding(Encoding::BINARY)
+ StringIO.new(raw_post)
+ else
+ body_stream
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 322
-def body
- if raw_post = get_header("RAW_POST_DATA")
- raw_post = raw_post.dup.force_encoding(Encoding::BINARY)
- StringIO.new(raw_post)
- else
- body_stream
- end
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 417
+ def commit_flash
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 417
-def commit_flash
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 259
+ def content_length
+ super.to_i
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 259
-def content_length
- super.to_i
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 78
+ def controller_class
+ params = path_parameters
+ params[:action] ||= "index"
+ controller_class_for(params[:controller])
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 78
-def controller_class
- params = path_parameters
- params[:action] ||= "index"
- controller_class_for(params[:controller])
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 84
+ def controller_class_for(name)
+ if name
+ controller_param = name.underscore
+ const_name = "#{controller_param.camelize}Controller"
+ ActiveSupport::Dependencies.constantize(const_name)
+ else
+ PASS_NOT_FOUND
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 84
-def controller_class_for(name)
- if name
- controller_param = name.underscore
- const_name = "#{controller_param.camelize}Controller"
- ActiveSupport::Dependencies.constantize(const_name)
- else
- PASS_NOT_FOUND
- end
-end
- # File actionpack/lib/action_dispatch/middleware/cookies.rb, line 11
+ def cookie_jar
+ fetch_header("action_dispatch.cookies".freeze) do
+ self.cookie_jar = Cookies::CookieJar.build(self, cookies)
+ end
+ end
- - Source: - -
- -# File actionpack/lib/action_dispatch/http/request.rb, line 339
+ def form_data?
+ FORM_DATA_MEDIA_TYPES.include?(media_type)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 339
-def form_data?
- FORM_DATA_MEDIA_TYPES.include?(media_type)
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 238
+ def fullpath
+ @fullpath ||= super
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 238
-def fullpath
- @fullpath ||= super
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 199
+ def headers
+ @headers ||= Http::Headers.new(self)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 199
-def headers
- @headers ||= Http::Headers.new(self)
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 168
+ def http_auth_salt
+ get_header "action_dispatch.http_auth_salt"
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 168
-def http_auth_salt
- get_header "action_dispatch.http_auth_salt"
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 272
+ def ip
+ @ip ||= super
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 272
-def ip
- @ip ||= super
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 97
+ def key?(key)
+ has_header? key
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 97
-def key?(key)
- has_header? key
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 404
+ def local?
+ LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 404
-def local?
- LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 413
+ def logger
+ get_header("action_dispatch.logger".freeze)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 413
-def logger
- get_header("action_dispatch.logger".freeze)
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 254
+ def media_type
+ content_mime_type.to_s
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 254
-def media_type
- content_mime_type.to_s
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 187
+ def method
+ @method ||= check_method(get_header("rack.methodoverride.original_method") || get_header("REQUEST_METHOD"))
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 187
-def method
- @method ||= check_method(get_header("rack.methodoverride.original_method") || get_header("REQUEST_METHOD"))
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 192
+ def method_symbol
+ HTTP_METHOD_LOOKUP[method]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 192
-def method_symbol
- HTTP_METHOD_LOOKUP[method]
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 227
+ def original_fullpath
+ @original_fullpath ||= (get_header("ORIGINAL_FULLPATH") || fullpath)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 227
-def original_fullpath
- @original_fullpath ||= (get_header("ORIGINAL_FULLPATH") || fullpath)
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 246
+ def original_url
+ base_url + original_fullpath
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 246
-def original_url
- base_url + original_fullpath
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 311
+ def raw_post
+ unless has_header? "RAW_POST_DATA"
+ raw_post_body = body
+ set_header("RAW_POST_DATA", raw_post_body.read(content_length))
+ raw_post_body.rewind if raw_post_body.respond_to?(:rewind)
+ end
+ get_header "RAW_POST_DATA"
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 311
-def raw_post
- unless has_header? "RAW_POST_DATA"
- raw_post_body = body
- set_header("RAW_POST_DATA", raw_post_body.read(content_length))
- raw_post_body.rewind if raw_post_body.respond_to?(:rewind)
- end
- get_header "RAW_POST_DATA"
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 278
+ def remote_ip
+ @remote_ip ||= (get_header("action_dispatch.remote_ip") || ip).to_s
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 278
-def remote_ip
- @remote_ip ||= (get_header("action_dispatch.remote_ip") || ip).to_s
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 282
+ def remote_ip=(remote_ip)
+ set_header "action_dispatch.remote_ip".freeze, remote_ip
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 282
-def remote_ip=(remote_ip)
- set_header "action_dispatch.remote_ip".freeze, remote_ip
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 294
+ def request_id
+ get_header ACTION_DISPATCH_REQUEST_ID
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 294
-def request_id
- get_header ACTION_DISPATCH_REQUEST_ID
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 134
+ def request_method
+ @request_method ||= check_method(super)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 134
-def request_method
- @request_method ||= check_method(super)
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 180
+ def request_method_symbol
+ HTTP_METHOD_LOOKUP[request_method]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 180
-def request_method_symbol
- HTTP_METHOD_LOOKUP[request_method]
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 408
+ def request_parameters=(params)
+ raise if params.nil?
+ set_header("action_dispatch.request.request_parameters".freeze, params)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 408
-def request_parameters=(params)
- raise if params.nil?
- set_header("action_dispatch.request.request_parameters".freeze, params)
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 349
+ def reset_session
+ if session && session.respond_to?(:destroy)
+ session.destroy
+ else
+ self.session = {}
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 349
-def reset_session
- if session && session.respond_to?(:destroy)
- session.destroy
- else
- self.session = {}
- end
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 214
-def send_early_hints(links)
- return unless env["rack.early_hints"]
+
+
+
+ 📝 Source code
+
- env["rack.early_hints"].call(links)
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 214
+ def send_early_hints(links)
+ return unless env["rack.early_hints"]
+
+ env["rack.early_hints"].call(links)
+ end
+
+ 🔎 See on GitHub
+
+
+
+
# File actionpack/lib/action_dispatch/http/request.rb, line 305
+ def server_software
+ (get_header("SERVER_SOFTWARE") && /^([a-zA-Z]+)/ =~ get_header("SERVER_SOFTWARE")) ? $1.downcase : nil
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 305
-def server_software
- (get_header("SERVER_SOFTWARE") && /^([a-zA-Z]+)/ =~ get_header("SERVER_SOFTWARE")) ? $1.downcase : nil
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 361
+ def session_options=(options)
+ Session::Options.set self, options
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 361
-def session_options=(options)
- Session::Options.set self, options
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 420
+ def ssl?
+ super || scheme == "wss".freeze
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 420
-def ssl?
- super || scheme == "wss".freeze
-end
- # File actionpack/lib/action_dispatch/http/request.rb, line 266
+ def xml_http_request?
+ get_header("HTTP_X_REQUESTED_WITH") =~ /XMLHttpRequest/i
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/request.rb, line 266
-def xml_http_request?
- get_header("HTTP_X_REQUESTED_WITH") =~ /XMLHttpRequest/i
-end
- # File actionpack/lib/action_dispatch/testing/request_encoder.rb, line 7
+ def accept_header; end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/request_encoder.rb, line 7
-def accept_header; end
- # File actionpack/lib/action_dispatch/testing/request_encoder.rb, line 6
+ def content_type; end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/request_encoder.rb, line 6
-def content_type; end
- # File actionpack/lib/action_dispatch/testing/request_encoder.rb, line 8
+ def encode_params(params); params; end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/request_encoder.rb, line 8
-def encode_params(params); params; end
- # File actionpack/lib/action_dispatch/testing/request_encoder.rb, line 9
+ def response_parser; -> body { body }; end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/request_encoder.rb, line 9
-def response_parser; -> body { body }; end
- # File actionpack/lib/action_dispatch/middleware/request_id.rb, line 20
+ def initialize(app)
+ @app = app
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/request_id.rb, line 20
-def initialize(app)
- @app = app
-end
- # File actionpack/lib/action_dispatch/middleware/request_id.rb, line 24
+ def call(env)
+ req = ActionDispatch::Request.new env
+ req.request_id = make_request_id(req.x_request_id)
+ @app.call(env).tap { |_status, headers, _body| headers[X_REQUEST_ID] = req.request_id }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/request_id.rb, line 24
-def call(env)
- req = ActionDispatch::Request.new env
- req.request_id = make_request_id(req.x_request_id)
- @app.call(env).tap { |_status, headers, _body| headers[X_REQUEST_ID] = req.request_id }
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 151
+ def self.create(status = 200, header = {}, body = [], default_headers: self.default_headers)
+ header = merge_default_headers(header, default_headers)
+ new status, header, body
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 151
-def self.create(status = 200, header = {}, body = [], default_headers: self.default_headers)
- header = merge_default_headers(header, default_headers)
- new status, header, body
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 156
+ def self.merge_default_headers(original, default)
+ default.respond_to?(:merge) ? default.merge(original) : original
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 156
-def self.merge_default_headers(original, default)
- default.respond_to?(:merge) ? default.merge(original) : original
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 163
-def initialize(status = 200, header = {}, body = [])
- super()
+
+
+
+ 📝 Source code
+
- @header = Header.new(self, header)
+ # File actionpack/lib/action_dispatch/http/response.rb, line 163
+ def initialize(status = 200, header = {}, body = [])
+ super()
- self.body, self.status = body, status
+ @header = Header.new(self, header)
- @cv = new_cond
- @committed = false
- @sending = false
- @sent = false
+ self.body, self.status = body, status
- prepare_cache_control!
+ @cv = new_cond
+ @committed = false
+ @sending = false
+ @sent = false
- yield self if block_given?
-end
-
# File actionpack/lib/action_dispatch/http/response.rb, line 368
+ def abort
+ if stream.respond_to?(:abort)
+ stream.abort
+ elsif stream.respond_to?(:close)
+ # `stream.close` should really be reserved for a close from the
+ # other direction, but we must fall back to it for
+ # compatibility.
+ stream.close
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 368
-def abort
- if stream.respond_to?(:abort)
- stream.abort
- elsif stream.respond_to?(:close)
- # `stream.close` should really be reserved for a close from the
- # other direction, but we must fall back to it for
- # compatibility.
- stream.close
- end
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 185
+ def await_commit
+ synchronize do
+ @cv.wait_until { @committed }
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 185
-def await_commit
- synchronize do
- @cv.wait_until { @committed }
- end
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 191
+ def await_sent
+ synchronize { @cv.wait_until { @sent } }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 191
-def await_sent
- synchronize { @cv.wait_until { @sent } }
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 302
+ def body
+ @stream.body
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 302
-def body
- @stream.body
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 311
+ def body=(body)
+ if body.respond_to?(:to_path)
+ @stream = body
+ else
+ synchronize do
+ @stream = build_buffer self, munge_body_object(body)
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 311
-def body=(body)
- if body.respond_to?(:to_path)
- @stream = body
- else
- synchronize do
- @stream = build_buffer self, munge_body_object(body)
- end
- end
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 355
+ def body_parts
+ parts = []
+ @stream.each { |x| parts << x }
+ parts
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 355
-def body_parts
- parts = []
- @stream.each { |x| parts << x }
- parts
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 272
+ def charset
+ header_info = parsed_content_type_header
+ header_info.charset || self.class.default_charset
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 272
-def charset
- header_info = parsed_content_type_header
- header_info.charset || self.class.default_charset
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 261
+ def charset=(charset)
+ content_type = parsed_content_type_header.mime_type
+ if false == charset
+ set_content_type content_type, nil
+ else
+ set_content_type content_type, charset || self.class.default_charset
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 261
-def charset=(charset)
- content_type = parsed_content_type_header.mime_type
- if false == charset
- set_content_type content_type, nil
- else
- set_content_type content_type, charset || self.class.default_charset
- end
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 364
+ def close
+ stream.close if stream.respond_to?(:close)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 364
-def close
- stream.close if stream.respond_to?(:close)
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 283
+ def code
+ @status.to_s
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 283
-def code
- @status.to_s
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 195
+ def commit!
+ synchronize do
+ before_committed
+ @committed = true
+ @cv.broadcast
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 195
-def commit!
- synchronize do
- before_committed
- @committed = true
- @cv.broadcast
- end
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 219
+ def committed?; synchronize { @committed }; end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 219
-def committed?; synchronize { @committed }; end
- # File actionpack/lib/action_dispatch/http/response.rb, line 246
+ def content_type
+ parsed_content_type_header.mime_type
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 246
-def content_type
- parsed_content_type_header.mime_type
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 228
+ def content_type=(content_type)
+ return unless content_type
+ new_header_info = parse_content_type(content_type.to_s)
+ prev_header_info = parsed_content_type_header
+ charset = new_header_info.charset || prev_header_info.charset
+ charset ||= self.class.default_charset unless prev_header_info.mime_type
+ set_content_type new_header_info.mime_type, charset
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 228
-def content_type=(content_type)
- return unless content_type
- new_header_info = parse_content_type(content_type.to_s)
- prev_header_info = parsed_content_type_header
- charset = new_header_info.charset || prev_header_info.charset
- charset ||= self.class.default_charset unless prev_header_info.mime_type
- set_content_type new_header_info.mime_type, charset
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 392
+ def cookies
+ cookies = {}
+ if header = get_header(SET_COOKIE)
+ header = header.split("\n") if header.respond_to?(:to_str)
+ header.each do |cookie|
+ if pair = cookie.split(";").first
+ key, value = pair.split("=").map { |v| Rack::Utils.unescape(v) }
+ cookies[key] = value
+ end
+ end
+ end
+ cookies
+ end
- - Source: - -
- -# File actionpack/lib/action_dispatch/http/response.rb, line 183
+ def delete_header(key); headers.delete key; end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 183
-def delete_header(key); headers.delete key; end
- # File actionpack/lib/action_dispatch/http/response.rb, line 74
+ def each(&block)
+ sending!
+ x = @stream.each(&block)
+ sent!
+ x
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 74
-def each(&block)
- sending!
- x = @stream.each(&block)
- sent!
- x
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 181
+ def get_header(key); headers[key]; end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 181
-def get_header(key); headers[key]; end
- # File actionpack/lib/action_dispatch/http/response.rb, line 180
+ def has_header?(key); headers.key? key; end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 180
-def has_header?(key); headers.key? key; end
- # File actionpack/lib/action_dispatch/http/response.rb, line 295
+ def message
+ Rack::Utils::HTTP_STATUS_CODES[@status]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 295
-def message
- Rack::Utils::HTTP_STATUS_CODES[@status]
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 351
+ def reset_body!
+ @stream = build_buffer(self, [])
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 351
-def reset_body!
- @stream = build_buffer(self, [])
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 278
+ def response_code
+ @status
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 278
-def response_code
- @status
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 346
+ def send_file(path)
+ commit!
+ @stream = FileBody.new(path)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 346
-def send_file(path)
- commit!
- @stream = FileBody.new(path)
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 203
+ def sending!
+ synchronize do
+ before_sending
+ @sending = true
+ @cv.broadcast
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 203
-def sending!
- synchronize do
- before_sending
- @sending = true
- @cv.broadcast
- end
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 218
+ def sending?; synchronize { @sending }; end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 218
-def sending?; synchronize { @sending }; end
- # File actionpack/lib/action_dispatch/http/response.rb, line 250
+ def sending_file=(v)
+ if true == v
+ self.charset = false
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 250
-def sending_file=(v)
- if true == v
- self.charset = false
- end
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 211
+ def sent!
+ synchronize do
+ @sent = true
+ @cv.broadcast
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 211
-def sent!
- synchronize do
- @sent = true
- @cv.broadcast
- end
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 220
+ def sent?; synchronize { @sent }; end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 220
-def sent?; synchronize { @sent }; end
- # File actionpack/lib/action_dispatch/http/response.rb, line 182
+ def set_header(key, v); headers[key] = v; end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 182
-def set_header(key, v); headers[key] = v; end
- # File actionpack/lib/action_dispatch/http/response.rb, line 223
+ def status=(status)
+ @status = Rack::Utils.status_code(status)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 223
-def status=(status)
- @status = Rack::Utils.status_code(status)
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 383
+ def to_a
+ commit!
+ rack_response @status, @header.to_hash
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 383
-def to_a
- commit!
- rack_response @status, @header.to_hash
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 306
+ def write(string)
+ @stream.write string
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 306
-def write(string)
- @stream.write string
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 470
+ def initialize(response)
+ @response = response
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 470
-def initialize(response)
- @response = response
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 484
+ def body
+ @response.body
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 484
-def body
- @response.body
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 478
+ def close
+ # Rack "close" maps to Response#abort, and *not* Response#close
+ # (which is used when the controller's finished writing)
+ @response.abort
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 478
-def close
- # Rack "close" maps to Response#abort, and *not* Response#close
- # (which is used when the controller's finished writing)
- @response.abort
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 474
+ def each(*args, &block)
+ @response.each(*args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 474
-def each(*args, &block)
- @response.each(*args, &block)
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 488
+ def respond_to?(method, include_private = false)
+ if method.to_s == "to_path"
+ @response.stream.respond_to?(method)
+ else
+ super
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 488
-def respond_to?(method, include_private = false)
- if method.to_s == "to_path"
- @response.stream.respond_to?(method)
- else
- super
- end
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 500
+ def to_ary
+ nil
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 500
-def to_ary
- nil
-end
- # File actionpack/lib/action_dispatch/http/response.rb, line 496
+ def to_path
+ @response.stream.to_path
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/http/response.rb, line 496
-def to_path
- @response.stream.to_path
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 130
+ def initialize
+ @buffer = []
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 130
-def initialize
- @buffer = []
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 146
+ def header(routes)
+ @buffer << draw_header(routes)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 146
-def header(routes)
- @buffer << draw_header(routes)
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 150
- def no_routes(routes)
- @buffer <<
- if routes.none?
- <<-MESSAGE.strip_heredoc
- You don't have any routes defined!
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/action_dispatch/routing/inspector.rb, line 150
+ def no_routes(routes)
+ @buffer <<
+ if routes.none?
+ <<-MESSAGE.strip_heredoc
+ You don't have any routes defined!
Please add some routes in config/routes.rb.
-
MESSAGE
- else
- "No routes were found for this controller"
- end
- @buffer << "For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html."
- end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 134
+ def result
+ @buffer.join("\n")
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 134
-def result
- @buffer.join("\n")
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 142
+ def section(routes)
+ @buffer << draw_section(routes)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 142
-def section(routes)
- @buffer << draw_section(routes)
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 138
+ def section_title(title)
+ @buffer << "\n#{title}:"
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 138
-def section_title(title)
- @buffer << "\n#{title}:"
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 188
+ def initialize(view)
+ @view = view
+ @buffer = []
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 188
-def initialize(view)
- @view = view
- @buffer = []
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 202
+ def header(routes)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 202
-def header(routes)
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 205
- def no_routes(*)
- @buffer << <<-MESSAGE.strip_heredoc
- <p>You don't have any routes defined!</p>
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/action_dispatch/routing/inspector.rb, line 205
+ def no_routes(*)
+ @buffer << <<-MESSAGE.strip_heredoc
+ <p>You don't have any routes defined!</p>
<ul>
<li>Please add some routes in <tt>config/routes.rb</tt>.</li>
<li>
@@ -193,12 +191,14 @@
<a href="http://guides.rubyonrails.org/routing.html">Rails Routing from the Outside In</a>.
</li>
</ul>
-
MESSAGE
- end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 218
+ def result
+ @view.raw @view.render(layout: "routes/table") {
+ @view.raw @buffer.join("\n")
+ }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 218
-def result
- @view.raw @view.render(layout: "routes/table") {
- @view.raw @buffer.join("\n")
- }
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 197
+ def section(routes)
+ @buffer << @view.render(partial: "routes/route", collection: routes)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 197
-def section(routes)
- @buffer << @view.render(partial: "routes/route", collection: routes)
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 193
+ def section_title(title)
+ @buffer << %(<tr><th colspan="4">#{title}</th></tr>)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 193
-def section_title(title)
- @buffer << %(<tr><th colspan="4">#{title}</th></tr>)
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 397
+ def self.normalize_name(name)
+ normalize_path(name)[1..-1].tr("/", "_")
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 397
-def self.normalize_name(name)
- normalize_path(name)[1..-1].tr("/", "_")
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 391
+ def self.normalize_path(path)
+ path = Journey::Router::Utils.normalize_path(path)
+ path.gsub!(%r{/(\(+)/?}, '\1/') unless path =~ %r{^/(\(+[^)]+\)){1,}$}
+ path
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 391
-def self.normalize_path(path)
- path = Journey::Router::Utils.normalize_path(path)
- path.gsub!(%r{/(\(+)/?}, '\1/') unless path =~ %r{^/(\(+[^)]+\)){1,}$}
- path
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 634
+ def default_url_options=(options)
+ @set.default_url_options = options
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 634
-def default_url_options=(options)
- @set.default_url_options = options
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 646
+ def has_named_route?(name)
+ @set.named_routes.key? name
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 646
-def has_named_route?(name)
- @set.named_routes.key? name
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 582
+ def match(path, options = nil)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 582
-def match(path, options = nil)
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 604
- def mount(app, options = nil)
- if options
- path = options.delete(:at)
- elsif Hash === app
- options = app
- app, path = options.find { |k, _| k.respond_to?(:call) }
- options.delete(app) if app
- end
-
- raise ArgumentError, "A rack application must be specified" unless app.respond_to?(:call)
- raise ArgumentError, <<-MSG.strip_heredoc unless path
- Must be called with mount point
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/action_dispatch/routing/mapper.rb, line 604
+ def mount(app, options = nil)
+ if options
+ path = options.delete(:at)
+ elsif Hash === app
+ options = app
+ app, path = options.find { |k, _| k.respond_to?(:call) }
+ options.delete(app) if app
+ end
+
+ raise ArgumentError, "A rack application must be specified" unless app.respond_to?(:call)
+ raise ArgumentError, <<-MSG.strip_heredoc unless path
+ Must be called with mount point
mount SomeRackApp, at: "some_route"
or
mount(SomeRackApp => "some_route")
-
MSG
+ MSG
- rails_app = rails_app? app
- options[:as] ||= app_name(app, rails_app)
+ rails_app = rails_app? app
+ options[:as] ||= app_name(app, rails_app)
- target_as = name_for_action(options[:as], path)
- options[:via] ||= :all
+ target_as = name_for_action(options[:as], path)
+ options[:via] ||= :all
- match(path, options.merge(to: app, anchor: false, format: false))
+ match(path, options.merge(to: app, anchor: false, format: false))
- define_generate_prefix(app, target_as) if rails_app
- self
- end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 639
+ def with_default_scope(scope, &block)
+ scope(scope) do
+ instance_exec(&block)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 639
-def with_default_scope(scope, &block)
- scope(scope) do
- instance_exec(&block)
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 2021
+ def concern(name, callable = nil, &block)
+ callable ||= lambda { |mapper, options| mapper.instance_exec(options, &block) }
+ @concerns[name] = callable
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 2021
-def concern(name, callable = nil, &block)
- callable ||= lambda { |mapper, options| mapper.instance_exec(options, &block) }
- @concerns[name] = callable
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 2037
+ def concerns(*args)
+ options = args.extract_options!
+ args.flatten.each do |name|
+ if concern = @concerns[name]
+ concern.call(self, options)
+ else
+ raise ArgumentError, "No concern named #{name} was found!"
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 2037
-def concerns(*args)
- options = args.extract_options!
- args.flatten.each do |name|
- if concern = @concerns[name]
- concern.call(self, options)
- else
- raise ArgumentError, "No concern named #{name} was found!"
- end
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 2097
+ def direct(name, options = {}, &block)
+ unless @scope.root?
+ raise RuntimeError, "The direct method can't be used inside a routes scope block"
+ end
+
+ @set.add_url_helper(name, options, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 2097
-def direct(name, options = {}, &block)
- unless @scope.root?
- raise RuntimeError, "The direct method can't be used inside a routes scope block"
- end
-
- @set.add_url_helper(name, options, &block)
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 2149
+ def resolve(*args, &block)
+ unless @scope.root?
+ raise RuntimeError, "The resolve method can't be used inside a routes scope block"
+ end
+
+ options = args.extract_options!
+ args = args.flatten(1)
+
+ args.each do |klass|
+ @set.add_polymorphic_mapping(klass, options, &block)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 2149
-def resolve(*args, &block)
- unless @scope.root?
- raise RuntimeError, "The resolve method can't be used inside a routes scope block"
- end
-
- options = args.extract_options!
- args = args.flatten(1)
-
- args.each do |klass|
- @set.add_polymorphic_mapping(klass, options, &block)
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 735
+ def delete(*args, &block)
+ map_method(:delete, args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 735
-def delete(*args, &block)
- map_method(:delete, args, &block)
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 703
+ def get(*args, &block)
+ map_method(:get, args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 703
-def get(*args, &block)
- map_method(:get, args, &block)
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 719
+ def patch(*args, &block)
+ map_method(:patch, args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 719
-def patch(*args, &block)
- map_method(:patch, args, &block)
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 711
+ def post(*args, &block)
+ map_method(:post, args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 711
-def post(*args, &block)
- map_method(:post, args, &block)
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 727
+ def put(*args, &block)
+ map_method(:put, args, &block)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 727
-def put(*args, &block)
- map_method(:put, args, &block)
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1483
+ def collection
+ unless resource_scope?
+ raise ArgumentError, "can't use collection outside resource(s) scope"
+ end
+
+ with_scope_level(:collection) do
+ path_scope(parent_resource.collection_scope) do
+ yield
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1483
-def collection
- unless resource_scope?
- raise ArgumentError, "can't use collection outside resource(s) scope"
- end
-
- with_scope_level(:collection) do
- path_scope(parent_resource.collection_scope) do
- yield
- end
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1580
+ def match(path, *rest, &block)
+ if rest.empty? && Hash === path
+ options = path
+ path, to = options.find { |name, _value| name.is_a?(String) }
+
+ raise ArgumentError, "Route path not specified" if path.nil?
+
+ case to
+ when Symbol
+ options[:action] = to
+ when String
+ if to =~ /#/
+ options[:to] = to
+ else
+ options[:controller] = to
+ end
+ else
+ options[:to] = to
+ end
+
+ options.delete(path)
+ paths = [path]
+ else
+ options = rest.pop || {}
+ paths = [path] + rest
+ end
+
+ if options.key?(:defaults)
+ defaults(options.delete(:defaults)) { map_match(paths, options, &block) }
+ else
+ map_match(paths, options, &block)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1580
-def match(path, *rest, &block)
- if rest.empty? && Hash === path
- options = path
- path, to = options.find { |name, _value| name.is_a?(String) }
-
- raise ArgumentError, "Route path not specified" if path.nil?
-
- case to
- when Symbol
- options[:action] = to
- when String
- if to =~ /#/
- options[:to] = to
- else
- options[:controller] = to
- end
- else
- options[:to] = to
- end
-
- options.delete(path)
- paths = [path]
- else
- options = rest.pop || {}
- paths = [path] + rest
- end
-
- if options.key?(:defaults)
- defaults(options.delete(:defaults)) { map_match(paths, options, &block) }
- else
- map_match(paths, options, &block)
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1506
+ def member
+ unless resource_scope?
+ raise ArgumentError, "can't use member outside resource(s) scope"
+ end
+
+ with_scope_level(:member) do
+ if shallow?
+ shallow_scope {
+ path_scope(parent_resource.member_scope) { yield }
+ }
+ else
+ path_scope(parent_resource.member_scope) { yield }
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1506
-def member
- unless resource_scope?
- raise ArgumentError, "can't use member outside resource(s) scope"
- end
-
- with_scope_level(:member) do
- if shallow?
- shallow_scope {
- path_scope(parent_resource.member_scope) { yield }
- }
- else
- path_scope(parent_resource.member_scope) { yield }
- end
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1555
+ def namespace(path, options = {})
+ if resource_scope?
+ nested { super }
+ else
+ super
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1555
-def namespace(path, options = {})
- if resource_scope?
- nested { super }
- else
- super
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1534
+ def nested
+ unless resource_scope?
+ raise ArgumentError, "can't use nested outside resource(s) scope"
+ end
+
+ with_scope_level(:nested) do
+ if shallow? && shallow_nesting_depth >= 1
+ shallow_scope do
+ path_scope(parent_resource.nested_scope) do
+ scope(nested_options) { yield }
+ end
+ end
+ else
+ path_scope(parent_resource.nested_scope) do
+ scope(nested_options) { yield }
+ end
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1534
-def nested
- unless resource_scope?
- raise ArgumentError, "can't use nested outside resource(s) scope"
- end
-
- with_scope_level(:nested) do
- if shallow? && shallow_nesting_depth >= 1
- shallow_scope do
- path_scope(parent_resource.nested_scope) do
- scope(nested_options) { yield }
- end
- end
- else
- path_scope(parent_resource.nested_scope) do
- scope(nested_options) { yield }
- end
- end
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1522
+ def new
+ unless resource_scope?
+ raise ArgumentError, "can't use new outside resource(s) scope"
+ end
+
+ with_scope_level(:new) do
+ path_scope(parent_resource.new_scope(action_path(:new))) do
+ yield
+ end
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1522
-def new
- unless resource_scope?
- raise ArgumentError, "can't use new outside resource(s) scope"
- end
-
- with_scope_level(:new) do
- path_scope(parent_resource.new_scope(action_path(:new))) do
- yield
- end
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1280
+ def resource(*resources, &block)
+ options = resources.extract_options!.dup
+
+ if apply_common_behavior_for(:resource, resources, options, &block)
+ return self
+ end
+
+ with_scope_level(:resource) do
+ options = apply_action_options options
+ resource_scope(SingletonResource.new(resources.pop, api_only?, @scope[:shallow], options)) do
+ yield if block_given?
+
+ concerns(options[:concerns]) if options[:concerns]
+
+ new do
+ get :new
+ end if parent_resource.actions.include?(:new)
+
+ set_member_mappings_for_resource
+
+ collection do
+ post :create
+ end if parent_resource.actions.include?(:create)
+ end
+ end
+
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1280
-def resource(*resources, &block)
- options = resources.extract_options!.dup
-
- if apply_common_behavior_for(:resource, resources, options, &block)
- return self
- end
-
- with_scope_level(:resource) do
- options = apply_action_options options
- resource_scope(SingletonResource.new(resources.pop, api_only?, @scope[:shallow], options)) do
- yield if block_given?
-
- concerns(options[:concerns]) if options[:concerns]
-
- new do
- get :new
- end if parent_resource.actions.include?(:new)
-
- set_member_mappings_for_resource
-
- collection do
- post :create
- end if parent_resource.actions.include?(:create)
- end
- end
-
- self
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1441
+ def resources(*resources, &block)
+ options = resources.extract_options!.dup
+
+ if apply_common_behavior_for(:resources, resources, options, &block)
+ return self
+ end
+
+ with_scope_level(:resources) do
+ options = apply_action_options options
+ resource_scope(Resource.new(resources.pop, api_only?, @scope[:shallow], options)) do
+ yield if block_given?
+
+ concerns(options[:concerns]) if options[:concerns]
+
+ collection do
+ get :index if parent_resource.actions.include?(:index)
+ post :create if parent_resource.actions.include?(:create)
+ end
+
+ new do
+ get :new
+ end if parent_resource.actions.include?(:new)
+
+ set_member_mappings_for_resource
+ end
+ end
+
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1441
-def resources(*resources, &block)
- options = resources.extract_options!.dup
-
- if apply_common_behavior_for(:resources, resources, options, &block)
- return self
- end
-
- with_scope_level(:resources) do
- options = apply_action_options options
- resource_scope(Resource.new(resources.pop, api_only?, @scope[:shallow], options)) do
- yield if block_given?
-
- concerns(options[:concerns]) if options[:concerns]
-
- collection do
- get :index if parent_resource.actions.include?(:index)
- post :create if parent_resource.actions.include?(:create)
- end
-
- new do
- get :new
- end if parent_resource.actions.include?(:new)
-
- set_member_mappings_for_resource
- end
- end
-
- self
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1255
+ def resources_path_names(options)
+ @scope[:path_names].merge!(options)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1255
-def resources_path_names(options)
- @scope[:path_names].merge!(options)
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1627
+ def root(path, options = {})
+ if path.is_a?(String)
+ options[:to] = path
+ elsif path.is_a?(Hash) && options.empty?
+ options = path
+ else
+ raise ArgumentError, "must be called with a path and/or options"
+ end
+
+ if @scope.resources?
+ with_scope_level(:root) do
+ path_scope(parent_resource.path) do
+ match_root_route(options)
+ end
+ end
+ else
+ match_root_route(options)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1627
-def root(path, options = {})
- if path.is_a?(String)
- options[:to] = path
- elsif path.is_a?(Hash) && options.empty?
- options = path
- else
- raise ArgumentError, "must be called with a path and/or options"
- end
-
- if @scope.resources?
- with_scope_level(:root) do
- path_scope(parent_resource.path) do
- match_root_route(options)
- end
- end
- else
- match_root_route(options)
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1563
+ def shallow
+ @scope = @scope.new(shallow: true)
+ yield
+ ensure
+ @scope = @scope.parent
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1563
-def shallow
- @scope = @scope.new(shallow: true)
- yield
-ensure
- @scope = @scope.parent
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1570
+ def shallow?
+ !parent_resource.singleton? && @scope[:shallow]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1570
-def shallow?
- !parent_resource.singleton? && @scope[:shallow]
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1827
+ def api_only? # :doc:
+ @set.api_only?
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1827
-def api_only? # :doc:
- @set.api_only?
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1815
+ def set_member_mappings_for_resource # :doc:
+ member do
+ get :edit if parent_resource.actions.include?(:edit)
+ get :show if parent_resource.actions.include?(:show)
+ if parent_resource.actions.include?(:update)
+ patch :update
+ put :update
+ end
+ delete :destroy if parent_resource.actions.include?(:destroy)
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1815
-def set_member_mappings_for_resource # :doc:
- member do
- get :edit if parent_resource.actions.include?(:edit)
- get :show if parent_resource.actions.include?(:show)
- if parent_resource.actions.include?(:update)
- patch :update
- put :update
- end
- delete :destroy if parent_resource.actions.include?(:destroy)
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1711
+ def with_scope_level(kind) # :doc:
+ @scope = @scope.new_level(kind)
+ yield
+ ensure
+ @scope = @scope.parent
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1711
-def with_scope_level(kind) # :doc:
- @scope = @scope.new_level(kind)
- yield
-ensure
- @scope = @scope.parent
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1007
+ def constraints(constraints = {})
+ scope(constraints: constraints) { yield }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1007
-def constraints(constraints = {})
- scope(constraints: constraints) { yield }
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 892
+ def controller(controller)
+ @scope = @scope.new(controller: controller)
+ yield
+ ensure
+ @scope = @scope.parent
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 892
-def controller(controller)
- @scope = @scope.new(controller: controller)
- yield
-ensure
- @scope = @scope.parent
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 1016
+ def defaults(defaults = {})
+ @scope = @scope.new(defaults: merge_defaults_scope(@scope[:defaults], defaults))
+ yield
+ ensure
+ @scope = @scope.parent
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1016
-def defaults(defaults = {})
- @scope = @scope.new(defaults: merge_defaults_scope(@scope[:defaults], defaults))
- yield
-ensure
- @scope = @scope.parent
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 937
+ def namespace(path, options = {})
+ path = path.to_s
+
+ defaults = {
+ module: path,
+ as: options.fetch(:as, path),
+ shallow_path: options.fetch(:path, path),
+ shallow_prefix: options.fetch(:as, path)
+ }
+
+ path_scope(options.delete(:path) { path }) do
+ scope(defaults.merge!(options)) { yield }
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 937
-def namespace(path, options = {})
- path = path.to_s
-
- defaults = {
- module: path,
- as: options.fetch(:as, path),
- shallow_path: options.fetch(:path, path),
- shallow_prefix: options.fetch(:as, path)
- }
-
- path_scope(options.delete(:path) { path }) do
- scope(defaults.merge!(options)) { yield }
- end
-end
- # File actionpack/lib/action_dispatch/routing/mapper.rb, line 833
+ def scope(*args)
+ options = args.extract_options!.dup
+ scope = {}
+
+ options[:path] = args.flatten.join("/") if args.any?
+ options[:constraints] ||= {}
+
+ unless nested_scope?
+ options[:shallow_path] ||= options[:path] if options.key?(:path)
+ options[:shallow_prefix] ||= options[:as] if options.key?(:as)
+ end
+
+ if options[:constraints].is_a?(Hash)
+ defaults = options[:constraints].select do |k, v|
+ URL_OPTIONS.include?(k) && (v.is_a?(String) || v.is_a?(Integer))
+ end
+
+ options[:defaults] = defaults.merge(options[:defaults] || {})
+ else
+ block, options[:constraints] = options[:constraints], {}
+ end
+
+ if options.key?(:only) || options.key?(:except)
+ scope[:action_options] = { only: options.delete(:only),
+ except: options.delete(:except) }
+ end
+
+ if options.key? :anchor
+ raise ArgumentError, "anchor is ignored unless passed to `match`"
+ end
+
+ @scope.options.each do |option|
+ if option == :blocks
+ value = block
+ elsif option == :options
+ value = options
+ else
+ value = options.delete(option) { POISON }
+ end
+
+ unless POISON == value
+ scope[option] = send("merge_#{option}_scope", @scope[option], value)
+ end
+ end
+
+ @scope = @scope.new scope
+ yield
+ self
+ ensure
+ @scope = @scope.parent
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/mapper.rb, line 833
-def scope(*args)
- options = args.extract_options!.dup
- scope = {}
-
- options[:path] = args.flatten.join("/") if args.any?
- options[:constraints] ||= {}
-
- unless nested_scope?
- options[:shallow_path] ||= options[:path] if options.key?(:path)
- options[:shallow_prefix] ||= options[:as] if options.key?(:as)
- end
-
- if options[:constraints].is_a?(Hash)
- defaults = options[:constraints].select do |k, v|
- URL_OPTIONS.include?(k) && (v.is_a?(String) || v.is_a?(Integer))
- end
-
- options[:defaults] = defaults.merge(options[:defaults] || {})
- else
- block, options[:constraints] = options[:constraints], {}
- end
-
- if options.key?(:only) || options.key?(:except)
- scope[:action_options] = { only: options.delete(:only),
- except: options.delete(:except) }
- end
-
- if options.key? :anchor
- raise ArgumentError, "anchor is ignored unless passed to `match`"
- end
-
- @scope.options.each do |option|
- if option == :blocks
- value = block
- elsif option == :options
- value = options
- else
- value = options.delete(option) { POISON }
- end
-
- unless POISON == value
- scope[option] = send("merge_#{option}_scope", @scope[option], value)
- end
- end
-
- @scope = @scope.new scope
- yield
- self
-ensure
- @scope = @scope.parent
-end
- # File actionpack/lib/action_dispatch/routing/redirection.rb, line 95
+ def inspect
+ "redirect(#{status}, #{block})"
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/redirection.rb, line 95
-def inspect
- "redirect(#{status}, #{block})"
-end
- # File actionpack/lib/action_dispatch/routing/redirection.rb, line 83
+ def path(params, request)
+ if block.match(URL_PARTS)
+ path = interpolation_required?($1, params) ? $1 % escape_path(params) : $1
+ query = interpolation_required?($2, params) ? $2 % escape(params) : $2
+ fragment = interpolation_required?($3, params) ? $3 % escape_fragment(params) : $3
+
+ "#{path}#{query}#{fragment}"
+ else
+ interpolation_required?(block, params) ? block % escape(params) : block
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/redirection.rb, line 83
-def path(params, request)
- if block.match(URL_PARTS)
- path = interpolation_required?($1, params) ? $1 % escape_path(params) : $1
- query = interpolation_required?($2, params) ? $2 % escape(params) : $2
- fragment = interpolation_required?($3, params) ? $3 % escape_fragment(params) : $3
-
- "#{path}#{query}#{fragment}"
- else
- interpolation_required?(block, params) ? block % escape(params) : block
- end
-end
- # File actionpack/lib/action_dispatch/routing/polymorphic_routes.rb, line 125
+ def polymorphic_path(record_or_hash_or_array, options = {})
+ if Hash === record_or_hash_or_array
+ options = record_or_hash_or_array.merge(options)
+ record = options.delete :id
+ return polymorphic_path record, options
+ end
+
+ if mapping = polymorphic_mapping(record_or_hash_or_array)
+ return mapping.call(self, [record_or_hash_or_array, options], true)
+ end
+
+ opts = options.dup
+ action = opts.delete :action
+ type = :path
+
+ HelperMethodBuilder.polymorphic_method self,
+ record_or_hash_or_array,
+ action,
+ type,
+ opts
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/polymorphic_routes.rb, line 125
-def polymorphic_path(record_or_hash_or_array, options = {})
- if Hash === record_or_hash_or_array
- options = record_or_hash_or_array.merge(options)
- record = options.delete :id
- return polymorphic_path record, options
- end
-
- if mapping = polymorphic_mapping(record_or_hash_or_array)
- return mapping.call(self, [record_or_hash_or_array, options], true)
- end
-
- opts = options.dup
- action = opts.delete :action
- type = :path
-
- HelperMethodBuilder.polymorphic_method self,
- record_or_hash_or_array,
- action,
- type,
- opts
-end
- # File actionpack/lib/action_dispatch/routing/polymorphic_routes.rb, line 101
+ def polymorphic_url(record_or_hash_or_array, options = {})
+ if Hash === record_or_hash_or_array
+ options = record_or_hash_or_array.merge(options)
+ record = options.delete :id
+ return polymorphic_url record, options
+ end
+
+ if mapping = polymorphic_mapping(record_or_hash_or_array)
+ return mapping.call(self, [record_or_hash_or_array, options], false)
+ end
+
+ opts = options.dup
+ action = opts.delete :action
+ type = opts.delete(:routing_type) || :url
+
+ HelperMethodBuilder.polymorphic_method self,
+ record_or_hash_or_array,
+ action,
+ type,
+ opts
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/polymorphic_routes.rb, line 101
-def polymorphic_url(record_or_hash_or_array, options = {})
- if Hash === record_or_hash_or_array
- options = record_or_hash_or_array.merge(options)
- record = options.delete :id
- return polymorphic_url record, options
- end
-
- if mapping = polymorphic_mapping(record_or_hash_or_array)
- return mapping.call(self, [record_or_hash_or_array, options], false)
- end
-
- opts = options.dup
- action = opts.delete :action
- type = opts.delete(:routing_type) || :url
-
- HelperMethodBuilder.polymorphic_method self,
- record_or_hash_or_array,
- action,
- type,
- opts
-end
- # File actionpack/lib/action_dispatch/routing/redirection.rb, line 187
+ def redirect(*args, &block)
+ options = args.extract_options!
+ status = options.delete(:status) || 301
+ path = args.shift
+
+ return OptionRedirect.new(status, options) if options.any?
+ return PathRedirect.new(status, path) if String === path
+
+ block = path if path.respond_to? :call
+ raise ArgumentError, "redirection argument not supported" unless block
+ Redirect.new status, block
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/redirection.rb, line 187
-def redirect(*args, &block)
- options = args.extract_options!
- status = options.delete(:status) || 301
- path = args.shift
-
- return OptionRedirect.new(status, options) if options.any?
- return PathRedirect.new(status, path) if String === path
-
- block = path if path.respond_to? :call
- raise ArgumentError, "redirection argument not supported" unless block
- Redirect.new status, block
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 41
+ def action
+ parts.include?(:action) ? ":action" : requirements[:action]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 41
-def action
- parts.include?(:action) ? ":action" : requirements[:action]
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 13
+ def constraints
+ requirements.except(:controller, :action)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 13
-def constraints
- requirements.except(:controller, :action)
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 37
+ def controller
+ parts.include?(:controller) ? ":controller" : requirements[:controller]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 37
-def controller
- parts.include?(:controller) ? ":controller" : requirements[:controller]
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 9
+ def endpoint
+ app.dispatcher? ? "#{controller}##{action}" : rack_app.inspect
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 9
-def endpoint
- app.dispatcher? ? "#{controller}##{action}" : rack_app.inspect
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 49
+ def engine?
+ app.engine?
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 49
-def engine?
- app.engine?
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 45
+ def internal?
+ internal
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 45
-def internal?
- internal
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 25
+ def name
+ super.to_s
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 25
-def name
- super.to_s
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 21
+ def path
+ super.spec.to_s
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 21
-def path
- super.spec.to_s
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 17
+ def rack_app
+ app.rack_app
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 17
-def rack_app
- app.rack_app
-end
- # File actionpack/lib/action_dispatch/routing/inspector.rb, line 29
+ def reqs
+ @reqs ||= begin
+ reqs = endpoint
+ reqs += " #{constraints}" unless constraints.empty?
+ reqs
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/inspector.rb, line 29
-def reqs
- @reqs ||= begin
- reqs = endpoint
- reqs += " #{constraints}" unless constraints.empty?
- reqs
- end
-end
- # File actionpack/lib/action_dispatch/routing/url_for.rb, line 106
+ def initialize(*)
+ @_routes = nil
+ super
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/url_for.rb, line 106
-def initialize(*)
- @_routes = nil
- super
-end
- # File actionpack/lib/action_dispatch/routing/url_for.rb, line 212
+ def route_for(name, *args)
+ public_send(:"#{name}_url", *args)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/url_for.rb, line 212
-def route_for(name, *args)
- public_send(:"#{name}_url", *args)
-end
- # File actionpack/lib/action_dispatch/routing/url_for.rb, line 168
+ def url_for(options = nil)
+ full_url_for(options)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/url_for.rb, line 168
-def url_for(options = nil)
- full_url_for(options)
-end
- # File actionpack/lib/action_dispatch/routing/url_for.rb, line 114
+ def url_options
+ default_url_options
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/url_for.rb, line 114
-def url_options
- default_url_options
-end
- # File actionpack/lib/action_dispatch/routing/url_for.rb, line 218
+ def optimize_routes_generation?
+ _routes.optimize_routes_generation? && default_url_options.empty?
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/url_for.rb, line 218
-def optimize_routes_generation?
- _routes.optimize_routes_generation? && default_url_options.empty?
-end
- # File actionpack/lib/action_dispatch/routing/url_for.rb, line 231
+ def _routes_context # :doc:
+ self
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/url_for.rb, line 231
-def _routes_context # :doc:
- self
-end
- # File actionpack/lib/action_dispatch/routing/url_for.rb, line 224
+ def _with_routes(routes) # :doc:
+ old_routes, @_routes = @_routes, routes
+ yield
+ ensure
+ @_routes = old_routes
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/routing/url_for.rb, line 224
-def _with_routes(routes) # :doc:
- old_routes, @_routes = @_routes, routes
- yield
-ensure
- @_routes = old_routes
-end
- # File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 96
+ def generate_sid
+ Rack::Session::SessionId.new(super)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 96
-def generate_sid
- Rack::Session::SessionId.new(super)
-end
- # File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 16
+ def initialize(app, options = {})
+ @cache = options[:cache] || Rails.cache
+ options[:expire_after] ||= @cache.options[:expires_in]
+ super
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 16
-def initialize(app, options = {})
- @cache = options[:cache] || Rails.cache
- options[:expire_after] ||= @cache.options[:expires_in]
- super
-end
- # File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 42
+ def delete_session(env, sid, options)
+ @cache.delete(cache_key(sid.private_id))
+ @cache.delete(cache_key(sid.public_id))
+ generate_sid
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 42
-def delete_session(env, sid, options)
- @cache.delete(cache_key(sid.private_id))
- @cache.delete(cache_key(sid.public_id))
- generate_sid
-end
- # File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 23
+ def find_session(env, sid)
+ unless sid && (session = get_session_with_fallback(sid))
+ sid, session = generate_sid, {}
+ end
+ [sid, session]
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 23
-def find_session(env, sid)
- unless sid && (session = get_session_with_fallback(sid))
- sid, session = generate_sid, {}
- end
- [sid, session]
-end
- # File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 31
+ def write_session(env, sid, session, options)
+ key = cache_key(sid.private_id)
+ if session
+ @cache.write(key, session, expires_in: options[:expire_after])
+ else
+ @cache.delete(key)
+ end
+ sid
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 31
-def write_session(env, sid, session, options)
- key = cache_key(sid.private_id)
- if session
- @cache.write(key, session, expires_in: options[:expire_after])
- else
- @cache.delete(key)
- end
- sid
-end
- # File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 21
+ def initialize(app, options = {})
+ options[:key] ||= "_session_id"
+ super
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 21
-def initialize(app, options = {})
- options[:key] ||= "_session_id"
- super
-end
- # File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 26
+ def generate_sid
+ sid = SecureRandom.hex(16)
+ sid.encode!(Encoding::UTF_8)
+ sid
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 26
-def generate_sid
- sid = SecureRandom.hex(16)
- sid.encode!(Encoding::UTF_8)
- sid
-end
- # File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 34
+ def initialize_sid # :doc:
+ @default_options.delete(:sidbits)
+ @default_options.delete(:secure_random)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 34
-def initialize_sid # :doc:
- @default_options.delete(:sidbits)
- @default_options.delete(:secure_random)
-end
- # File actionpack/lib/action_dispatch/middleware/session/cookie_store.rb, line 64
+ def initialize(app, options = {})
+ super(app, options.merge!(cookie_only: true))
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/cookie_store.rb, line 64
-def initialize(app, options = {})
- super(app, options.merge!(cookie_only: true))
-end
- # File actionpack/lib/action_dispatch/middleware/session/cookie_store.rb, line 68
+ def delete_session(req, session_id, options)
+ new_sid = generate_sid unless options[:drop]
+ # Reset hash and Assign the new session id
+ req.set_header("action_dispatch.request.unsigned_session_cookie", new_sid ? { "session_id" => new_sid.public_id } : {})
+ new_sid
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/cookie_store.rb, line 68
-def delete_session(req, session_id, options)
- new_sid = generate_sid unless options[:drop]
- # Reset hash and Assign the new session id
- req.set_header("action_dispatch.request.unsigned_session_cookie", new_sid ? { "session_id" => new_sid.public_id } : {})
- new_sid
-end
- # File actionpack/lib/action_dispatch/middleware/session/cookie_store.rb, line 75
+ def load_session(req)
+ stale_session_check! do
+ data = unpacked_cookie_data(req)
+ data = persistent_session_id!(data)
+ [Rack::Session::SessionId.new(data["session_id"]), data]
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/cookie_store.rb, line 75
-def load_session(req)
- stale_session_check! do
- data = unpacked_cookie_data(req)
- data = persistent_session_id!(data)
- [Rack::Session::SessionId.new(data["session_id"]), data]
- end
-end
- # File actionpack/lib/action_dispatch/middleware/session/cookie_store.rb, line 58
+ def initialize(session_id, cookie_value = {})
+ super(session_id)
+ @cookie_value = cookie_value
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/cookie_store.rb, line 58
-def initialize(session_id, cookie_value = {})
- super(session_id)
- @cookie_value = cookie_value
-end
- # File actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb, line 22
+ def initialize(app, options = {})
+ options[:expire_after] ||= options[:expires]
+ super
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb, line 22
-def initialize(app, options = {})
- options[:expire_after] ||= options[:expires]
- super
-end
- # File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 49
+ def extract_session_id(env)
+ stale_session_check! { super }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 49
-def extract_session_id(env)
- stale_session_check! { super }
-end
- # File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 45
+ def load_session(env)
+ stale_session_check! { super }
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 45
-def load_session(env)
- stale_session_check! { super }
-end
- # File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 53
+ def stale_session_check!
+ yield
+ rescue ArgumentError => argument_error
+ if argument_error.message =~ %r{undefined class/module ([\w:]*\w)}
+ begin
+ # Note that the regexp does not allow $1 to end with a ':'.
+ $1.constantize
+ rescue LoadError, NameError
+ raise ActionDispatch::Session::SessionRestoreError
+ end
+ retry
+ else
+ raise
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/session/abstract_store.rb, line 53
-def stale_session_check!
- yield
-rescue ArgumentError => argument_error
- if argument_error.message =~ %r{undefined class/module ([\w:]*\w)}
- begin
- # Note that the regexp does not allow $1 to end with a ':'.
- $1.constantize
- rescue LoadError, NameError
- raise ActionDispatch::Session::SessionRestoreError
- end
- retry
- else
- raise
- end
-end
- # File actionpack/lib/action_dispatch/middleware/show_exceptions.rb, line 26
+ def initialize(app, exceptions_app)
+ @app = app
+ @exceptions_app = exceptions_app
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/show_exceptions.rb, line 26
-def initialize(app, exceptions_app)
- @app = app
- @exceptions_app = exceptions_app
-end
- # File actionpack/lib/action_dispatch/middleware/show_exceptions.rb, line 31
+ def call(env)
+ request = ActionDispatch::Request.new env
+ @app.call(env)
+ rescue Exception => exception
+ if request.show_exceptions?
+ render_exception(request, exception)
+ else
+ raise exception
+ end
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/show_exceptions.rb, line 31
-def call(env)
- request = ActionDispatch::Request.new env
- @app.call(env)
-rescue Exception => exception
- if request.show_exceptions?
- render_exception(request, exception)
- else
- raise exception
- end
-end
- # File actionpack/lib/action_dispatch/middleware/static.rb, line 111
+ def initialize(app, path, index: "index", headers: {})
+ @app = app
+ @file_handler = FileHandler.new(path, index: index, headers: headers)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/static.rb, line 111
-def initialize(app, path, index: "index", headers: {})
- @app = app
- @file_handler = FileHandler.new(path, index: index, headers: headers)
-end
- # File actionpack/lib/action_dispatch/middleware/static.rb, line 116
+ def call(env)
+ req = Rack::Request.new env
+
+ if req.get? || req.head?
+ path = req.path_info.chomp("/".freeze)
+ if match = @file_handler.match?(path)
+ req.path_info = match
+ return @file_handler.serve(req)
+ end
+ end
+
+ @app.call(req.env)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/middleware/static.rb, line 116
-def call(env)
- req = Rack::Request.new env
-
- if req.get? || req.head?
- path = req.path_info.chomp("/".freeze)
- if match = @file_handler.match?(path)
- req.path_info = match
- return @file_handler.serve(req)
- end
- end
-
- @app.call(req.env)
-end
- # File actionpack/lib/action_dispatch/system_test_case.rb, line 137
+ def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400], options: {})
+ self.driver = SystemTesting::Driver.new(driver, using: using, screen_size: screen_size, options: options)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/system_test_case.rb, line 137
-def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400], options: {})
- self.driver = SystemTesting::Driver.new(driver, using: using, screen_size: screen_size, options: options)
-end
- # File actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb, line 36
+ def take_failed_screenshot
+ take_screenshot if failed? && supports_screenshot?
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb, line 36
-def take_failed_screenshot
- take_screenshot if failed? && supports_screenshot?
-end
- # File actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb, line 24
+ def take_screenshot
+ save_image
+ puts display_image
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb, line 24
-def take_screenshot
- save_image
- puts display_image
-end
- # File actionpack/lib/action_dispatch/testing/test_process.rb, line 28
+ def assigns(key = nil)
+ raise NoMethodError,
+ "assigns has been extracted to a gem. To continue using it,
+ add `gem 'rails-controller-testing'` to your Gemfile."
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_process.rb, line 28
-def assigns(key = nil)
- raise NoMethodError,
- "assigns has been extracted to a gem. To continue using it,
- add `gem 'rails-controller-testing'` to your Gemfile."
-end
- # File actionpack/lib/action_dispatch/testing/test_process.rb, line 42
+ def cookies
+ @cookie_jar ||= Cookies::CookieJar.build(@request, @request.cookies)
+ end
- - Source: - -
- -# File actionpack/lib/action_dispatch/testing/test_process.rb, line 38
+ def flash
+ @request.flash
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_process.rb, line 38
-def flash
- @request.flash
-end
- # File actionpack/lib/action_dispatch/testing/test_process.rb, line 46
+ def redirect_to_url
+ @response.redirect_url
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_process.rb, line 46
-def redirect_to_url
- @response.redirect_url
-end
- # File actionpack/lib/action_dispatch/testing/test_process.rb, line 34
+ def session
+ @request.session
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_process.rb, line 34
-def session
- @request.session
-end
- # File actionpack/lib/action_dispatch/testing/test_process.rb, line 17
+ def fixture_file_upload(path, mime_type = nil, binary = false)
+ if self.class.respond_to?(:fixture_path) && self.class.fixture_path &&
+ !File.exist?(path)
+ path = File.join(self.class.fixture_path, path)
+ end
+ Rack::Test::UploadedFile.new(path, mime_type, binary)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_process.rb, line 17
-def fixture_file_upload(path, mime_type = nil, binary = false)
- if self.class.respond_to?(:fixture_path) && self.class.fixture_path &&
- !File.exist?(path)
- path = File.join(self.class.fixture_path, path)
- end
- Rack::Test::UploadedFile.new(path, mime_type, binary)
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 15
-def self.create(env = {})
- env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
- env["rack.request.cookie_hash"] ||= {}.with_indifferent_access
- new(default_env.merge(env))
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 15
+ def self.create(env = {})
+ env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
+ env["rack.request.cookie_hash"] ||= {}.with_indifferent_access
+ new(default_env.merge(env))
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 66
-def accept=(mime_types)
- delete_header("action_dispatch.request.accepts")
- set_header("HTTP_ACCEPT", Array(mime_types).collect(&:to_s).join(","))
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 66
+ def accept=(mime_types)
+ delete_header("action_dispatch.request.accepts")
+ set_header("HTTP_ACCEPT", Array(mime_types).collect(&:to_s).join(","))
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 46
-def action=(action_name)
- path_parameters[:action] = action_name.to_s
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 46
+ def action=(action_name)
+ path_parameters[:action] = action_name.to_s
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 30
-def host=(host)
- set_header("HTTP_HOST", host)
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 30
+ def host=(host)
+ set_header("HTTP_HOST", host)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 50
-def if_modified_since=(last_modified)
- set_header("HTTP_IF_MODIFIED_SINCE", last_modified)
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 50
+ def if_modified_since=(last_modified)
+ set_header("HTTP_IF_MODIFIED_SINCE", last_modified)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 54
-def if_none_match=(etag)
- set_header("HTTP_IF_NONE_MATCH", etag)
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 54
+ def if_none_match=(etag)
+ set_header("HTTP_IF_NONE_MATCH", etag)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 42
-def path=(path)
- set_header("PATH_INFO", path)
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 42
+ def path=(path)
+ set_header("PATH_INFO", path)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 34
-def port=(number)
- set_header("SERVER_PORT", number.to_i)
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 34
+ def port=(number)
+ set_header("SERVER_PORT", number.to_i)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 58
-def remote_addr=(addr)
- set_header("REMOTE_ADDR", addr)
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 58
+ def remote_addr=(addr)
+ set_header("REMOTE_ADDR", addr)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 26
-def request_method=(method)
- super(method.to_s.upcase)
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 26
+ def request_method=(method)
+ super(method.to_s.upcase)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 38
-def request_uri=(uri)
- set_header("REQUEST_URI", uri)
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 38
+ def request_uri=(uri)
+ set_header("REQUEST_URI", uri)
+ end
+
+ 🔎 See on GitHub
+
+ - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_request.rb, line 62
-def user_agent=(user_agent)
- set_header("HTTP_USER_AGENT", user_agent)
-end
- # File actionpack/lib/action_dispatch/testing/test_request.rb, line 62
+ def user_agent=(user_agent)
+ set_header("HTTP_USER_AGENT", user_agent)
+ end
+
+ 🔎 See on GitHub
+
+ # File actionpack/lib/action_dispatch/testing/test_response.rb, line 13
+ def self.from_response(response)
+ new response.status, response.headers, response.body
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_response.rb, line 13
-def self.from_response(response)
- new response.status, response.headers, response.body
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_response.rb, line 41
- def error?
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- The error? predicate is deprecated and will be removed in Rails 6.0.
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/action_dispatch/testing/test_response.rb, line 41
+ def error?
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ The error? predicate is deprecated and will be removed in Rails 6.0.
Please use server_error? as provided by Rack::Response::Helpers.
-
MSG
- server_error?
- end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_response.rb, line 32
- def missing?
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- The missing? predicate is deprecated and will be removed in Rails 6.0.
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/action_dispatch/testing/test_response.rb, line 32
+ def missing?
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ The missing? predicate is deprecated and will be removed in Rails 6.0.
Please use not_found? as provided by Rack::Response::Helpers.
-
MSG
- not_found?
- end
- # File actionpack/lib/action_dispatch/testing/test_response.rb, line 49
+ def parsed_body
+ @parsed_body ||= @response_parser.call(body)
+ end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_response.rb, line 49
-def parsed_body
- @parsed_body ||= @response_parser.call(body)
-end
- - Source: - -
-# File actionpack/lib/action_dispatch/testing/test_response.rb, line 23
- def success?
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- The success? predicate is deprecated and will be removed in Rails 6.0.
+
+
+
+ 📝 Source code
+
+
+ # File actionpack/lib/action_dispatch/testing/test_response.rb, line 23
+ def success?
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ The success? predicate is deprecated and will be removed in Rails 6.0.
Please use successful? as provided by Rack::Response::Helpers.
-
MSG
- successful?
- end
- # File actionmailer/lib/action_mailer/gem_version.rb, line 5
+ def self.gem_version
+ Gem::Version.new VERSION::STRING
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/gem_version.rb, line 5
-def self.gem_version
- Gem::Version.new VERSION::STRING
-end
- # File actionmailer/lib/action_mailer/version.rb, line 8
+ def self.version
+ gem_version
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/version.rb, line 8
-def self.version
- gem_version
-end
- # File actionmailer/lib/action_mailer/base.rb, line 521
+ def default(value = nil)
+ self.default_params = default_params.merge(value).freeze if value
+ default_params
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 521
-def default(value = nil)
- self.default_params = default_params.merge(value).freeze if value
- default_params
-end
- # File actionmailer/lib/action_mailer/base.rb, line 509
+ def mailer_name
+ @mailer_name ||= anonymous? ? "anonymous" : name.underscore
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 509
-def mailer_name
- @mailer_name ||= anonymous? ? "anonymous" : name.underscore
-end
- # File actionmailer/lib/action_mailer/base.rb, line 593
+ def initialize
+ super()
+ @_mail_was_called = false
+ @_message = Mail.new
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 593
-def initialize
- super()
- @_mail_was_called = false
- @_message = Mail.new
-end
- # File actionmailer/lib/action_mailer/base.rb, line 543
+ def receive(raw_mail)
+ ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
+ mail = Mail.new(raw_mail)
+ set_payload_for_mail(payload, mail)
+ new.receive(mail)
+ end
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 543
-def receive(raw_mail)
- ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
- mail = Mail.new(raw_mail)
- set_payload_for_mail(payload, mail)
- new.receive(mail)
- end
-end
- # File actionmailer/lib/action_mailer/base.rb, line 493
+ def register_interceptor(interceptor)
+ Mail.register_interceptor(observer_class_for(interceptor))
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 493
-def register_interceptor(interceptor)
- Mail.register_interceptor(observer_class_for(interceptor))
-end
- # File actionmailer/lib/action_mailer/base.rb, line 479
+ def register_interceptors(*interceptors)
+ interceptors.flatten.compact.each { |interceptor| register_interceptor(interceptor) }
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 479
-def register_interceptors(*interceptors)
- interceptors.flatten.compact.each { |interceptor| register_interceptor(interceptor) }
-end
- # File actionmailer/lib/action_mailer/base.rb, line 486
+ def register_observer(observer)
+ Mail.register_observer(observer_class_for(observer))
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 486
-def register_observer(observer)
- Mail.register_observer(observer_class_for(observer))
-end
- # File actionmailer/lib/action_mailer/base.rb, line 474
+ def register_observers(*observers)
+ observers.flatten.compact.each { |observer| register_observer(observer) }
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 474
-def register_observers(*observers)
- observers.flatten.compact.each { |observer| register_observer(observer) }
-end
- # File actionmailer/lib/action_mailer/base.rb, line 884
+ def self.supports_path? # :doc:
+ false
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 884
-def self.supports_path? # :doc:
- false
-end
- # File actionmailer/lib/action_mailer/base.rb, line 702
+ def attachments
+ if @_mail_was_called
+ LateAttachmentsProxy.new(@_message.attachments)
+ else
+ @_message.attachments
+ end
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 702
-def attachments
- if @_mail_was_called
- LateAttachmentsProxy.new(@_message.attachments)
- else
- @_message.attachments
- end
-end
- # File actionmailer/lib/action_mailer/base.rb, line 664
+ def headers(args = nil)
+ if args
+ @_message.headers(args)
+ else
+ @_message
+ end
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 664
-def headers(args = nil)
- if args
- @_message.headers(args)
- else
- @_message
- end
-end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 811
-def mail(headers = {}, &block)
- return message if @_mail_was_called && headers.blank? && !block
+
+
+
+ 📝 Source code
+
- # At the beginning, do not consider class default for content_type
- content_type = headers[:content_type]
+ # File actionmailer/lib/action_mailer/base.rb, line 811
+ def mail(headers = {}, &block)
+ return message if @_mail_was_called && headers.blank? && !block
- headers = apply_defaults(headers)
+ # At the beginning, do not consider class default for content_type
+ content_type = headers[:content_type]
- # Apply charset at the beginning so all fields are properly quoted
- message.charset = charset = headers[:charset]
+ headers = apply_defaults(headers)
- # Set configure delivery behavior
- wrap_delivery_behavior!(headers[:delivery_method], headers[:delivery_method_options])
+ # Apply charset at the beginning so all fields are properly quoted
+ message.charset = charset = headers[:charset]
- assign_headers_to_message(message, headers)
+ # Set configure delivery behavior
+ wrap_delivery_behavior!(headers[:delivery_method], headers[:delivery_method_options])
- # Render the templates and blocks
- responses = collect_responses(headers, &block)
- @_mail_was_called = true
+ assign_headers_to_message(message, headers)
- create_parts_from_responses(message, responses)
+ # Render the templates and blocks
+ responses = collect_responses(headers, &block)
+ @_mail_was_called = true
- # Setup content type, reapply charset and handle parts order
- message.content_type = set_content_type(message, content_type, headers[:content_type])
- message.charset = charset
+ create_parts_from_responses(message, responses)
- if message.multipart?
- message.body.set_sort_order(headers[:parts_order])
- message.body.sort_parts!
- end
+ # Setup content type, reapply charset and handle parts order
+ message.content_type = set_content_type(message, content_type, headers[:content_type])
+ message.charset = charset
- message
-end
-
# File actionmailer/lib/action_mailer/base.rb, line 626
+ def mailer_name
+ self.class.mailer_name
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 626
-def mailer_name
- self.class.mailer_name
-end
- # File actionmailer/lib/action_mailer/base.rb, line 878
+ def default_i18n_subject(interpolations = {}) # :doc:
+ mailer_scope = self.class.mailer_name.tr("/", ".")
+ I18n.t(:subject, interpolations.merge(scope: [mailer_scope, action_name], default: action_name.humanize))
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 878
-def default_i18n_subject(interpolations = {}) # :doc:
- mailer_scope = self.class.mailer_name.tr("/", ".")
- I18n.t(:subject, interpolations.merge(scope: [mailer_scope, action_name], default: action_name.humanize))
-end
- # File actionmailer/lib/action_mailer/base.rb, line 856
+ def set_content_type(m, user_content_type, class_default) # :doc:
+ params = m.content_type_parameters || {}
+ case
+ when user_content_type.present?
+ user_content_type
+ when m.has_attachments?
+ if m.attachments.detect(&:inline?)
+ ["multipart", "related", params]
+ else
+ ["multipart", "mixed", params]
+ end
+ when m.multipart?
+ ["multipart", "alternative", params]
+ else
+ m.content_type || class_default
+ end
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 856
-def set_content_type(m, user_content_type, class_default) # :doc:
- params = m.content_type_parameters || {}
- case
- when user_content_type.present?
- user_content_type
- when m.has_attachments?
- if m.attachments.detect(&:inline?)
- ["multipart", "related", params]
- else
- ["multipart", "mixed", params]
- end
- when m.multipart?
- ["multipart", "alternative", params]
- else
- m.content_type || class_default
- end
-end
- # File actionmailer/lib/action_mailer/base.rb, line 712
+ def []=(_name, _content); _raise_error end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 712
-def []=(_name, _content); _raise_error end
- # File actionmailer/lib/action_mailer/base.rb, line 711
+ def inline; _raise_error end
- - Source: - -
-# File actionmailer/lib/action_mailer/base.rb, line 711
-def inline; _raise_error end
- # File actionmailer/lib/action_mailer/collector.rb, line 12
+ def initialize(context, &block)
+ @context = context
+ @responses = []
+ @default_render = block
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/collector.rb, line 12
-def initialize(context, &block)
- @context = context
- @responses = []
- @default_render = block
-end
- # File actionmailer/lib/action_mailer/collector.rb, line 18
+ def any(*args, &block)
+ options = args.extract_options!
+ raise ArgumentError, "You have to supply at least one format" if args.empty?
+ args.each { |type| send(type, options.dup, &block) }
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/collector.rb, line 18
-def any(*args, &block)
- options = args.extract_options!
- raise ArgumentError, "You have to supply at least one format" if args.empty?
- args.each { |type| send(type, options.dup, &block) }
-end
- # File actionmailer/lib/action_mailer/collector.rb, line 25
+ def custom(mime, options = {})
+ options.reverse_merge!(content_type: mime.to_s)
+ @context.formats = [mime.to_sym]
+ options[:body] = block_given? ? yield : @default_render.call
+ @responses << options
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/collector.rb, line 25
-def custom(mime, options = {})
- options.reverse_merge!(content_type: mime.to_s)
- @context.formats = [mime.to_sym]
- options[:body] = block_given? ? yield : @default_render.call
- @responses << options
-end
- # File actionmailer/lib/action_mailer/delivery_methods.rb, line 50
+ def add_delivery_method(symbol, klass, default_options = {})
+ class_attribute(:"#{symbol}_settings") unless respond_to?(:"#{symbol}_settings")
+ send(:"#{symbol}_settings=", default_options)
+ self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/delivery_methods.rb, line 50
-def add_delivery_method(symbol, klass, default_options = {})
- class_attribute(:"#{symbol}_settings") unless respond_to?(:"#{symbol}_settings")
- send(:"#{symbol}_settings=", default_options)
- self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze
-end
- # File actionmailer/lib/action_mailer/log_subscriber.rb, line 10
+ def deliver(event)
+ info do
+ recipients = Array(event.payload[:to]).join(", ")
+ "Sent mail to #{recipients} (#{event.duration.round(1)}ms)"
+ end
+
+ debug { event.payload[:mail] }
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/log_subscriber.rb, line 10
-def deliver(event)
- info do
- recipients = Array(event.payload[:to]).join(", ")
- "Sent mail to #{recipients} (#{event.duration.round(1)}ms)"
- end
-
- debug { event.payload[:mail] }
-end
- # File actionmailer/lib/action_mailer/log_subscriber.rb, line 35
+ def logger
+ ActionMailer::Base.logger
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/log_subscriber.rb, line 35
-def logger
- ActionMailer::Base.logger
-end
- # File actionmailer/lib/action_mailer/log_subscriber.rb, line 26
+ def process(event)
+ debug do
+ mailer = event.payload[:mailer]
+ action = event.payload[:action]
+ "#{mailer}##{action}: processed outbound mail in #{event.duration.round(1)}ms"
+ end
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/log_subscriber.rb, line 26
-def process(event)
- debug do
- mailer = event.payload[:mailer]
- action = event.payload[:action]
- "#{mailer}##{action}: processed outbound mail in #{event.duration.round(1)}ms"
- end
-end
- # File actionmailer/lib/action_mailer/log_subscriber.rb, line 20
+ def receive(event)
+ info { "Received mail (#{event.duration.round(1)}ms)" }
+ debug { event.payload[:mail] }
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/log_subscriber.rb, line 20
-def receive(event)
- info { "Received mail (#{event.duration.round(1)}ms)" }
- debug { event.payload[:mail] }
-end
- # File actionmailer/lib/action_mailer/mail_helper.rb, line 43
+ def attachments
+ mailer.attachments
+ end
- - Source: - -
-# File actionmailer/lib/action_mailer/mail_helper.rb, line 43
-def attachments
- mailer.attachments
-end
- # File actionmailer/lib/action_mailer/mail_helper.rb, line 20
+ def block_format(text)
+ formatted = text.split(/\n\r?\n/).collect { |paragraph|
+ format_paragraph(paragraph)
+ }.join("\n\n")
+
+ # Make list points stand on their own line
+ formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { " #{$1} #{$2.strip}\n" }
+ formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { " #{$1} #{$2.strip}\n" }
+
+ formatted
+ end
- - Source: - -
-