`
orcl_zhang
  • 浏览: 243086 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

ActionController源码(待续)

阅读更多
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb
module ActionController #:nodoc:
class Base
    DEFAULT_RENDER_STATUS_CODE = "200 OK"

    include StatusCodes

    cattr_reader :protected_instance_variables
    # Controller specific instance variables which will not be accessible inside views.
    @@protected_instance_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
                                        @action_name @before_filter_chain_aborted @action_cache_path @_session @_headers @_params
                                        @_flash @_response)

    # Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
    # and images to a dedicated asset server away from the main web server. Example:
    #   ActionController::Base.asset_host = "http://assets.example.com"
    @@asset_host = ""
    cattr_accessor :asset_host

    # All requests are considered local by default, so everyone will be exposed to detailed debugging screens on errors.
    # When the application is ready to go public, this should be set to false, and the protected method <tt>local_request?</tt>
    # should instead be implemented in the controller to determine when debugging screens should be shown.
    @@consider_all_requests_local = true
    cattr_accessor :consider_all_requests_local

    # Indicates whether to allow concurrent action processing. Your
    # controller actions and any other code they call must also behave well
    # when called from concurrent threads. Turned off by default.
    @@allow_concurrency = false
    cattr_accessor :allow_concurrency

    # Modern REST web services often need to submit complex data to the web application.
    # The <tt>@@param_parsers</tt> hash lets you register handlers which will process the HTTP body and add parameters to the
    # <tt>params</tt> hash. These handlers are invoked for POST and PUT requests.
    #
    # By default <tt>application/xml</tt> is enabled. A XmlSimple class with the same param name as the root will be instantiated
    # in the <tt>params</tt>. This allows XML requests to mask themselves as regular form submissions, so you can have one
    # action serve both regular forms and web service requests.
    #
    # Example of doing your own parser for a custom content type:
    #
    #   ActionController::Base.param_parsers[Mime::Type.lookup('application/atom+xml')] = Proc.new do |data|
    #      node = REXML::Document.new(post)
    #     { node.root.name => node.root }
    #   end
    #
    # Note: Up until release 1.1 of Rails, Action Controller would default to using XmlSimple configured to discard the
    # root node for such requests. The new default is to keep the root, such that "<r><name>David</name></r>" results
    # in <tt>params[:r][:name]</tt> for "David" instead of <tt>params[:name]</tt>. To get the old behavior, you can
    # re-register XmlSimple as application/xml handler ike this:
    #
    #   ActionController::Base.param_parsers[Mime::XML] =
    #     Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) }
    #
    # A YAML parser is also available and can be turned on with:
    #
    #   ActionController::Base.param_parsers[Mime::YAML] = :yaml
    @@param_parsers = {}
    cattr_accessor :param_parsers

    # Controls the default charset for all renders.
    @@default_charset = "utf-8"
    cattr_accessor :default_charset

    # The logger is used for generating information on the action run-time (including benchmarking) if available.
    # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
    cattr_accessor :logger

    # Controls the resource action separator
    @@resource_action_separator = "/"
    cattr_accessor :resource_action_separator

    # Allow to override path names for default resources' actions
    @@resources_path_names = { :new => 'new', :edit => 'edit' }
    cattr_accessor :resources_path_names

    # Sets the token parameter name for RequestForgery. Calling +protect_from_forgery+
    # sets it to <tt>:authenticity_token</tt> by default.
    cattr_accessor :request_forgery_protection_token

    # Controls the IP Spoofing check when determining the remote IP.
    @@ip_spoofing_check = true
    cattr_accessor :ip_spoofing_check

    # Indicates whether or not optimise the generated named
    # route helper methods
    cattr_accessor :optimise_named_routes
    self.optimise_named_routes = true

    # Indicates whether the response format should be determined by examining the Accept HTTP header,
    # or by using the simpler params + ajax rules.
    #
    # If this is set to +true+ (the default) then +respond_to+ and +Request#format+ will take the Accept
    # header into account.  If it is set to false then the request format will be determined solely
    # by examining params[:format].  If params format is missing, the format will be either HTML or
    # Javascript depending on whether the request is an AJAX request.
    cattr_accessor :use_accept_header
    self.use_accept_header = true

    # Controls whether request forgergy protection is turned on or not. Turned off by default only in test mode.
    class_inheritable_accessor :allow_forgery_protection
    self.allow_forgery_protection = true

    # If you are deploying to a subdirectory, you will need to set
    # <tt>config.action_controller.relative_url_root</tt>
    # This defaults to ENV['RAILS_RELATIVE_URL_ROOT']
    cattr_accessor :relative_url_root
    self.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']

    # Holds the request object that's primarily used to get environment variables through access like
    # <tt>request.env["REQUEST_URI"]</tt>.
    attr_internal :request

    # Holds a hash of all the GET, POST, and Url parameters passed to the action. Accessed like <tt>params["post_id"]</tt>
    # to get the post_id. No type casts are made, so all values are returned as strings.
    attr_internal :params

    # Holds the response object that's primarily used to set additional HTTP headers through access like
    # <tt>response.headers["Cache-Control"] = "no-cache"</tt>. Can also be used to access the final body HTML after a template
    # has been rendered through response.body -- useful for <tt>after_filter</tt>s that wants to manipulate the output,
    # such as a OutputCompressionFilter.
    attr_internal :response

    # Holds a hash of objects in the session. Accessed like <tt>session[:person]</tt> to get the object tied to the "person"
    # key. The session will hold any type of object as values, but the key should be a string or symbol.
    attr_internal :session

    # Holds a hash of header names and values. Accessed like <tt>headers["Cache-Control"]</tt> to get the value of the Cache-Control
    # directive. Values should always be specified as strings.
    attr_internal :headers

    # Returns the name of the action this controller is processing.
    attr_accessor :action_name
  end
end


/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/module/attr_internal.rb
class Module
  # Declares an attribute reader backed by an internally-named instance variable.
  def attr_internal_reader(*attrs)
    attrs.each do |attr|
      module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end"
    end
  end

  # Declares an attribute writer backed by an internally-named instance variable.
  def attr_internal_writer(*attrs)
    attrs.each do |attr|
      module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end"
    end
  end

  # Declares an attribute reader and writer backed by an internally-named instance
  # variable.
  def attr_internal_accessor(*attrs)
    attr_internal_reader(*attrs)
    attr_internal_writer(*attrs)
  end

  alias_method :attr_internal, :attr_internal_accessor

  private
    mattr_accessor :attr_internal_naming_format
    self.attr_internal_naming_format = '@_%s'

    def attr_internal_ivar_name(attr)
      attr_internal_naming_format % attr
    end
end


/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/module/attribute_accessors.rb
# Extends the module object with module and instance accessors for class attributes, 
# just like the native attr* accessors for instance attributes.
#
#  module AppConfiguration
#    mattr_accessor :google_api_key
#    self.google_api_key = "123456789"
#
#    mattr_accessor :paypal_url
#    self.paypal_url = "www.sandbox.paypal.com"
#  end
#
#  AppConfiguration.google_api_key = "overriding the api key!"
class Module
  def mattr_reader(*syms)
    syms.each do |sym|
      next if sym.is_a?(Hash)
      class_eval(<<-EOS, __FILE__, __LINE__)
        unless defined? @@#{sym}  # unless defined? @@pagination_options
          @@#{sym} = nil          #   @@pagination_options = nil
        end                       # end
                                  #
        def self.#{sym}           # def self.pagination_options
          @@#{sym}                #   @@pagination_options
        end                       # end
                                  #
        def #{sym}                # def pagination_options
          @@#{sym}                #   @@pagination_options
        end                       # end
      EOS
    end
  end
  
  def mattr_writer(*syms)
    options = syms.extract_options!
    syms.each do |sym|
      class_eval(<<-EOS, __FILE__, __LINE__)
        unless defined? @@#{sym}                       # unless defined? @@pagination_options
          @@#{sym} = nil                               #   @@pagination_options = nil
        end                                            # end
                                                       #
        def self.#{sym}=(obj)                          # def self.pagination_options=(obj)
          @@#{sym} = obj                               #   @@pagination_options = obj
        end                                            # end
                                                       #
        #{"                                            #
        def #{sym}=(obj)                               # def pagination_options=(obj)
          @@#{sym} = obj                               #   @@pagination_options = obj
        end                                            # end
        " unless options[:instance_writer] == false }  # # instance writer above is generated unless options[:instance_writer] == false
      EOS
    end
  end
  
  def mattr_accessor(*syms)
    mattr_reader(*syms)
    mattr_writer(*syms)
  end
end
分享到:
评论

相关推荐

    Controller源码

    【标题】"Controller源码"涉及的是ASP.NET MVC3框架中的关键组件——Controller类的源代码分析。在ASP.NET MVC3中,Controller是应用程序的主要控制层,负责处理来自客户端的请求,协调应用逻辑,并返回相应的视图...

    9--[小黑点的旅行(未完待续)].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码

    9--[小黑点的旅行(未完待续)].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码9--[小黑点的旅行(未完待续)].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码9--[小黑点的旅行(未完待续)].zip...

    Spark-2.3.1源码解读

    Spark-2.3.1源码解读。 Spark Core源码阅读 Spark Context 阅读要点 Spark的缓存,变量,shuffle数据等清理及...PIDController源码赏析及 back pressure 实现思路 Streaming Context重点摘要 checkpoint 必知必会

    10个图书管理系统的源码

    这是我收集的10个图书管理系统的源码。各个系统实现的编程语言可能不同,有VB、VC、C#、C++、asp、php等等,有的系统功能比较复杂,有的比较简单。有的系统不仅包括源码和数据库,而且包括论文等设计文档。10个系统...

    unity摄像机控制系统源码Camera Controller 3.341

    unity摄像机控制系统源码Camera Controller 3.21 亲测可用,附带官方案例。 完整unitypackage,谢谢研究。 unity摄像机控制系统源码Camera Controller 3.21 Requires Unity 5.1.0 or higher. The perfect AAA ...

    饿了么源码 百度外卖源码 美团外卖源码 外卖系统源码

    订餐网,外卖网源码,带积分商城,商家系统,外卖网站建设! 系统特点: 周密策划、项目为先 "项目指导技术,技术服从项目",这是我们一贯秉承的原则,也是我们与其他系统开发商、网站建设公司的本质区别所在!我们...

    微信小程序源码下载 微信小程序源码下载 2000套微信小程序源码

    本资源包含2000套微信小程序的源码,对于开发者来说是一份宝贵的参考资料,可以用来学习、研究或者作为开发新项目的起点。 源码下载是开发者获取程序原始代码的方式,对于学习和理解编程逻辑至关重要。这些微信小...

    私服发布网站PHP源码

    3. **MVC模式**:考虑到源码的动态更新功能,它可能采用了Model-View-Controller(MVC)设计模式。这是一种将业务逻辑、数据处理和界面显示分离的方式,有助于提高代码可维护性和可扩展性。 4. **前端技术**:尽管...

    ssh框架项目源码ssh框架项目源码ssh框架项目源码

    ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh...

    视频播放网站源码

    6. **Mvcmediaplayer**:这可能是主要的项目源代码,基于MVC(Model-View-Controller)架构设计。MVC模式是一种常见的软件设计模式,用于分离业务逻辑、用户界面和数据模型。在视频播放网站中,模型负责处理数据,...

    C#项目源码大集合系列一

    源码01 销售管理系统 源码02 彩票分析系统 源码03 餐饮管理系统 源码04 C#点名程序 源码05 象棋游戏 源码06 变色球游戏 源码07 多功能计算器 源码08 记事本 源码09 简易画图程序 源码10 成绩管理系统 源码11 BBS论坛...

    jQuery in Action 及 源码 src 2

    jQuery in Action 及 源码 src 2

    51套经典企业网站源码(一)

    0001-2科技发展有限公司升级版源码 0001科技发展有限公司修正版源码 0002机械配件制造销售公司修正版源码 0003家具地板公司修正版源码 0004-1机械有限公司修正版源码 0004机械有限公司修正版源码 0005机械产品公司...

    移动医疗APP源码 android (安卓版)妙手医生源码

    移动医疗APP源码是开发医疗健康应用的核心组成部分,它包含了应用程序的所有逻辑和界面设计。在Android平台上,这种源码通常是用Java或Kotlin语言编写的,并使用Android Studio作为集成开发环境(IDE)。在这个案例...

    cocos creator完整麻将源码下载

    《cocos creator完整麻将源码解析与开发指南》 cocos Creator是一款强大的2D游戏开发引擎,被广泛应用于游戏开发,尤其是休闲娱乐类游戏,如麻将。本篇将深入探讨"麻将源码"这一主题,结合cocos Creator的特性,为...

    XILINXFPGA源码DDR2Controller

    XILINXFPGA源码DDR2 Controller提取方式是百度网盘分享地址

    公司产品展示网站源码

    【产品展示网站源码】是一种用于在线展示公司产品的软件代码,它构成了一个网站的基础结构,允许企业以有吸引力的方式向访客展示其商品或服务。此类源码通常包含前端和后端组件,前者负责用户界面的设计和交互,后者...

    Linux系统下dhcp源码

    Linux系统下的DHCP(Dynamic Host Configuration Protocol)源码解析 DHCP是一种网络协议,用于自动分配IP地址、子网掩码、默认网关等网络配置信息给网络中的设备。在Linux环境中,DHCP服务器通常使用isc-dhcp-...

    多功能在线报价系统源码

    【标题】:“多功能在线报价系统源码” 在线报价系统是一种基于网络的应用程序,它使得企业或个人能够方便快捷地提供产品或服务的价格信息给潜在客户。这个“多功能在线报价系统源码”是专为此目的设计的,允许用户...

    libevent源码深度剖析pdf

    为方便阅读,把blog上的libevent源码深度剖析系列文章整合成一个pdf。

Global site tag (gtag.js) - Google Analytics