123456789_123456789_123456789_123456789_123456789_

Module: AbstractController::Config

Do not use. This module is for internal use only.
Relationships & Source Files
Defined in: actionpack/lib/abstract_controller/config.rb

Class Method Summary

Class Method Details

.generate_accessors(owner, *keys)

Calling custom methods on the config instance goes through method_missing, which is slow. Using config#[] is faster and call-caches can cache it.

[ GitHub ]

  
# File 'actionpack/lib/abstract_controller/config.rb', line 8

def generate_accessors(owner, *keys)
  methods = []
  keys.each do |key|
    methods << "def #{key}; config[#{key.inspect}]; end"
    methods << "def #{key}=(value); config[#{key.inspect}] = value; end"
  end

  location = caller_locations(1, 1).first
  path = location&.path || __FILE__
  line = location&.lineno || __LINE__ - 6

  [owner, owner::ClassMethods].flatten.each do |owner|
    owner.class_eval(methods.join(";"), path, line)
  end
end