Rails源代码分析(29):回到ActionController(1)
来源:互联网 发布:语音朗读软件安卓版 编辑:程序博客网 时间:2024/05/22 15:25
前面那么长时间都是在分析Controller,基本有了比较清晰的认识。
现在回到controller里面看看还有哪些方面遗漏了
类方法:
- class << self
- # Factory for the standard create, process loop where the controller is discarded after processing.
- def process(request, response) #:nodoc:
- new.process(request, response)
- end
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "NeatController".
- def controller_class_name
- @controller_class_name ||= name.demodulize
- end
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "neat".
- def controller_name
- @controller_name ||= controller_class_name.sub(/Controller$/, '').underscore
- end
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "one_module/two_module/neat".
- def controller_path
- @controller_path ||= name.gsub(/Controller$/, '').underscore
- end
- # Return an array containing the names of public methods that have been marked hidden from the action processor.
- # By default, all methods defined in ActionController::Base and included modules are hidden.
- # More methods can be hidden using <tt>hide_actions</tt>.
- def hidden_actions # 无法通过action processor进入的方法
- unless read_inheritable_attribute(:hidden_actions)
- write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map(:to_s))
- end
- read_inheritable_attribute(:hidden_actions)
- end
- # Hide each of the given methods from being callable as actions.
- def hide_action(*names) # 添加无法通过action processor访问的方法
- write_inheritable_attribute(:hidden_actions, hidden_actions | names.map(:to_s))
- end
- ## View load paths determine the bases from which template references can be made. So a call to
- ## render("test/template") will be looked up in the view load paths array and the closest match will be
- ## returned.
- def view_paths
- @view_paths || superclass.view_paths
- end
- def view_paths=(value)
- @view_paths = value
- ActionView::TemplateFinder.process_view_paths(value) #查找view_path
- end
- # Adds a view_path to the front of the view_paths array.
- # If the current class has no view paths, copy them from
- # the superclass. This change will be visible for all future requests.
- #
- # ArticleController.prepend_view_path("views/default")
- # ArticleController.prepend_view_path(["views/default", "views/custom"])
- #
- def prepend_view_path(path)
- @view_paths = superclass.view_paths.dup if @view_paths.nil?
- view_paths.unshift(*path)
- ActionView::TemplateFinder.process_view_paths(path)
- end
- # Adds a view_path to the end of the view_paths array.
- # If the current class has no view paths, copy them from
- # the superclass. This change will be visible for all future requests.
- #
- # ArticleController.append_view_path("views/default")
- # ArticleController.append_view_path(["views/default", "views/custom"])
- #
- def append_view_path(path)
- @view_paths = superclass.view_paths.dup if @view_paths.nil?
- view_paths.push(*path)
- ActionView::TemplateFinder.process_view_paths(path)
- end
- # Replace sensitive parameter data from the request log.
- # Filters parameters that have any of the arguments as a substring.
- # Looks in all subhashes of the param hash for keys to filter.
- # If a block is given, each key and value of the parameter hash and all
- # subhashes is passed to it, the value or key
- # can be replaced using String#replace or similar method.
- #
- # Examples:
- # filter_parameter_logging
- # => Does nothing, just slows the logging process down
- #
- # filter_parameter_logging :password
- # => replaces the value to all keys matching /password/i with "[FILTERED]"
- #
- # filter_parameter_logging :foo, "bar"
- # => replaces the value to all keys matching /foo|bar/i with "[FILTERED]"
- #
- # filter_parameter_logging { |k,v| v.reverse! if k =~ /secret/i }
- # => reverses the value to all keys matching /secret/i
- #
- # filter_parameter_logging(:foo, "bar") { |k,v| v.reverse! if k =~ /secret/i }
- # => reverses the value to all keys matching /secret/i, and
- # replaces the value to all keys matching /foo|bar/i with "[FILTERED]"
- def filter_parameter_logging(*filter_words, &block)
- parameter_filter = Regexp.new(filter_words.collect{ |s| s.to_s }.join('|'), true) if filter_words.length > 0 # 构造需要过滤得参数
- define_method(:filter_parameters) do |unfiltered_parameters|
- filtered_parameters = {}
- unfiltered_parameters.each do |key, value|
- if key =~ parameter_filter # 如果需要过滤
- filtered_parameters[key] = '[FILTERED]'
- elsif value.is_a?(Hash)
- filtered_parameters[key] = filter_parameters(value)
- elsif block_given?
- key = key.dup
- value = value.dup if value
- yield key, value
- filtered_parameters[key] = value
- else
- filtered_parameters[key] = value
- end
- end
- filtered_parameters
- end
- protected :filter_parameters
- end
- # Don't render layouts for templates with the given extensions.
- def exempt_from_layout(*extensions)
- regexps = extensions.collect do |extension|
- extension.is_a?(Regexp) ? extension : //.#{Regexp.escape(extension.to_s)}$/
- end
- @@exempt_from_layout.merge regexps
- end
- end
- def url_for(options = nil) #:doc:
- case options || {}
- when String
- options
- when Hash
- @url.rewrite(rewrite_options(options))
- else
- polymorphic_url(options)
- end
- end
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "NeatController".
- def controller_class_name
- self.class.controller_class_name
- end
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "neat".
- def controller_name
- self.class.controller_name
- end
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "one_module/two_module/neat".
- def controller_path
- self.class.controller_path
- end
- def session_enabled?
- request.session_options && request.session_options[:disabled] != false
- end
- self.view_paths = []
- # View load paths for controller.
- def view_paths
- @template.finder.view_paths
- end
- def view_paths=(value)
- @template.finder.view_paths = value # Mutex needed
- end
- # Adds a view_path to the front of the view_paths array.
- # This change affects the current request only.
- #
- # self.prepend_view_path("views/default")
- # self.prepend_view_path(["views/default", "views/custom"])
- #
- def prepend_view_path(path)
- @template.finder.prepend_view_path(path) # Mutex needed
- end
- # Adds a view_path to the end of the view_paths array.
- # This change affects the current request only.
- #
- # self.append_view_path("views/default")
- # self.append_view_path(["views/default", "views/custom"])
- #
- def append_view_path(path)
- @template.finder.append_view_path(path) # Mutex needed
- end
- Rails源代码分析(29):回到ActionController(1)
- Rails源代码分析(7):ActionController::Filter(1)
- Rails源代码分析(10):ActionController::Layout(1)
- Rails源代码分析(17):ActionController::Caching(1)
- Rails源代码分析(30):ActionController::Routing(1)
- Rails源代码分析(5):ActionController概览
- Rails源代码分析(6):ActionController::Flash
- Rails源代码分析(12):ActionController::Benchmarking
- Rails源代码分析(13):ActionController::Rescue
- Rails源代码分析(14):ActionController::MimeResponds
- Rails源代码分析(15):ActionController::Helpers
- Rails源代码分析(16):ActionController::Cookies
- Rails源代码分析(23):ActionController::Verification
- Rails源代码分析(24):ActionController::Streaming
- Rails源代码分析(25):ActionController::SessionManagement
- Rails源代码分析(27):ActionController::RecordIdentifier
- Rails源代码分析(28):ActionController::RequestForgeryProtection
- Rails源代码分析(8):ActionController::Filter(2)
- MIME media types for ISUP and QSIG Objects RFC 3204 摘要
- document.all
- awt事件监听器对象实例
- WTL专栏
- 今天学习了一点ps的小技七,记录一下
- Rails源代码分析(29):回到ActionController(1)
- NS2返回值
- Seagull PHP框架学习教程之Seagull核心库
- 自动化(Automation)基础概念:接口描述语言(IDL)与类型库(TypeLib)
- struts-1.2.9-bin.zip下载
- eclipse3.1.1下载及汉化包[转]
- 第一篇博文!
- eclipse 3.4.1汉化
- bboss persistent 新增功能列表