railsでrenderを指定しないmethodがどのようにrender先を指定しているのか確認Try2

昨日の続き。

abstract_controller/rendering.rb内のRenderingモジュールのrenderで同じmoduleの_normalize_renderを呼び出し。

From: ~/demo_app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/abstract_controller/rendering.rb @ line 96 AbstractController::Rendering#render:

    95: def render(*args, &block)
 => 96:   binding.pry
    97:   options = _normalize_render(*args, &block)
    98:   self.response_body = render_to_body(options)
    99: end


From: ~/demo_app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/abstract_controller/rendering.rb @ line 97 AbstractController::Rendering#render:

    95: def render(*args, &block)
    96:   binding.pry
 => 97:   options = _normalize_render(*args, &block)
    98:   self.response_body = render_to_body(options)
    99: end

その中で、normalize_argsを呼び出している。直下にメソッドあるけど、次に呼び出しているのは、 action_controller/metal/rendering.rbのnormalize_argsですね。

From: ~/demo_app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/abstract_controller/rendering.rb @ line 153 AbstractController::Rendering#_normalize_render:

    152: def _normalize_render(*args, &block)
 => 153:   options = _normalize_args(*args, &block)
    154:   _normalize_options(options)
    155:   options
    156: end



From: ~/demo_app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_controller/metal/rendering.rb @ line 40 ActionController::Rendering#_normalize_args:

    39: def _normalize_args(action=nil, options={}, &blk) #:nodoc:
 => 40:   options = super
    41:   options[:update] = blk if block_given?
    42:   options
    43: end

そして、superの呼び出しで、abstract_controller/rendering.rbの_normalize_argsとなる。

From: ~/demo_app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/abstract_controller/rendering.rb @ line 162 AbstractController::Rendering#_normalize_args:

    161: def _normalize_args(action=nil, options={})
 => 162:   case action
    163:   when NilClass
    164:   when Hash
    165:     options = action
    166:   when String, Symbol
    167:     action = action.to_s
    168:     key = action.include?(?/) ? :file : :action
    169:     options[key] = action
    170:   else
    171:     options[:partial] = action
    172:   end
    173: 
    174:   options
    175: end

ここまでの流れを整理するとこんな感じ?

action_controller/metal/instrumentation.rb
ActionController::Instrumentation#render

この処理のsuperでは↓が呼び出される。

action_controller/metal/rendering.rb
ActionController::Rendering#render
(ActionController::Renderingは、AbstractController::Renderingをinclude)

さらにここのsuperでは↓が呼び出される。

1
abstract_controller/rendering.rb
AbstractController::Rendering#render

この中で、_normalize_renderを呼び出している。

2
abstract_controller/rendering.rb
AbstractController::Rendering#_normalize_render

_normalize_render内で最初に呼び出しているメソッド。

3
action_controller/metal/rendering.rb
ActionController::Rendering#_normalize_args

そして次のsuperメソッド

 4
abstract_controller/rendering.rb
AbstractController::Rendering#_normalize_args

で、この処理が完了すると、AbstractController::Rendering#_normalize_renderを呼び出している。 上で言うと、2に制御が戻りました。