The module nams "Rails"
基本都是一些类方法,本来也是作为服务类的。源码如下:
class << self def application @@application ||= nil end def application=(application) @@application = application end # The Configuration instance used to configure the Rails environment def configuration application.config end def initialize! application.initialize! end def initialized? @@initialized || false end def initialized=(initialized) @@initialized ||= initialized end def logger @@logger ||= nil end def logger=(logger) @@logger = logger end def backtrace_cleaner @@backtrace_cleaner ||= begin # Relies on Active Support, so we have to lazy load to postpone definition until AS has been loaded require 'rails/backtrace_cleaner' Rails::BacktraceCleaner.new end end def root application && application.config.root end def env @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development") end def env=(environment) @_env = ActiveSupport::StringInquirer.new(environment) end def cache RAILS_CACHE end # Returns all rails groups for loading based on: # # * The Rails environment; # * The environment variable RAILS_GROUPS; # * The optional envs given as argument and the hash with group dependencies; # # == Examples # # groups :assets => [:development, :test] # # # Returns # # => [:default, :development, :assets] for Rails.env == "development" # # => [:default, :production] for Rails.env == "production" # def groups(*groups) hash = groups.extract_options! env = Rails.env groups.unshift(:default, env) groups.concat ENV["RAILS_GROUPS"].to_s.split(",") groups.concat hash.map { |k,v| k if v.map(&:to_s).include?(env) } groups.compact! groups.uniq! groups end def version VERSION::STRING end def public_path application && application.paths["public"].first end end这里面的很多方法是服务的,比如查看配置,查看版本,等等。
重点说几个常用的:
* application
1.9.3p194 :001 > Rails.application.class
=> AppName::Application
* 查看Rails的配置
# The Configuration instance used to configure the Rails environment def configuration application.config end
1.9.3p194 :006 > Rails.configuration.class
=> Rails::Application::Configuration
1.9.3p194 :008 > Rails.configuration.session_store
=> ActionDispatch::Session::CookieStore
还有很多配置,随时补充吧,在这里查看配置很方便。
*cache 查看cache类型和配置
1.9.3p194 :010 > Rails.cache
=> #<ActiveSupport::Cache::FileStore:0x000000032fa898 @options={}, @cache_path="/mnt/ubuntu-64-disk-2/home
def cache RAILS_CACHE end
这里的cache居然还是个常量。
Rails::Info
autoload :Info, 'rails/info'
这个类显示了很多Rails的基本信息,很多Rails模块的很多用法,可以参考这个类是怎么使用的。
1.9.3p194 :001 > Rails::Info
(3.1ms) SELECT `schema_migrations`.`version` FROM `schema_migrations`
=> About your application's environment
Ruby version 1.9.3 (x86_64-linux)
RubyGems version 1.8.24
Rack version 1.4
Rails version 3.2.13
JavaScript Runtime therubyracer (V8)
Active Record version 3.2.13
Action Pack version 3.2.13
Active Resource version 3.2.13
Action Mailer version 3.2.13
Active Support version 3.2.13
Database schema version 20140613094339
autoload :InfoController, 'rails/info_controller'
rails模块中引入的这个类,代码很简单:
class Rails::InfoController < ActionController::Base def properties if consider_all_requests_local? || request.local? render :inline => Rails::Info.to_html else render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => :forbidden end end protected def consider_all_requests_local? Rails.application.config.consider_all_requests_local end end
就是把Rails的Info信息在浏览器显示一下。
可以看出这里是用了ActionController,那么我们认为,配置了路由,就可以访问了,不知rails自带的默认生成的代码是不是配置了此项。
我们来配置一下路由:
get 'rails/info/properties' => 'rails::info#properties' #testing rails info
好了在浏览器访问一下:
http://nihao.com:3000/rails/info/properties
果然是可以看到一个比较友好的表格,显示rails的详细信息。
+
+
+
0
-
-
-
相关推荐
ruby on rails 教程源码,配合原书使用
一个用Ruby on Rails搭建的图片分享的网站项目.完整源代码
rails-exporter-源码.rar
Rails进行敏捷Web开发(所有版本的源码rails3.0-4.0) 3.0,3.1,3.2,4.0
Webpacker:使用Webpack在Rails中管理类似app的JavaScript模块
rails_apps_composer, 一个 gem,为 Rails 启动应用程序创建 Rails 应用程序模板 Rails 应用编辑器 Rails 应用程序编辑器 gem 安装一个 命令行 工具来从"食谱"的Collection 组装 Rails 应用程序。"你可以使用 rails_...
ruby on rails社区网站开发源码
rails_semantic_logger, Rails 语义记录器用语义记录器替换 Rails 缺省记录器 Rails 语义记录器 语义记录器用语义记录器替代 Rails 缺省记录器。http://github.com/rocketjob/rails_semantic_logger文档有关完整文档...
Ruby on Rails Guides v2 - Ruby on Rails 4.2.5
shopping_card_rails-源码.rar
2-94街机外星风格射击游戏源码On Rails Shooter Template 1.202-94街机外星风格射击游戏源码On Rails Shooter Template 1.202-94街机外星风格射击游戏源码On Rails Shooter Template 1.202-94街机外星风格射击游戏...
InspiniaAdmin 2.6.1 Rails_Full_Version
你将学习一切Rails scaffolding的基本原理,以创建自定义的交互式网络应用程序,全部使用Rails的一套丰富的工具和MVC框架。 你将掌握数据库交互、Ajax和XML的集成、丰富的内容,甚至数据的动态图形——曾经要使用...
Ruby on Rails源代码
agile_web_development_with_rails_3rd_edition.9994652073.pdf
基于ruby on rails开发示例源码
ruby_on_rails 开发者实战 源代码上 1-12章 来之不易啊。仅供学习.
bhl_rails_solr-源码.rar
angular_rails_csrf-源码.rar
基于java的开发源码-Rails3消息队列系统 Sidekiq.zip 基于java的开发源码-Rails3消息队列系统 Sidekiq.zip 基于java的开发源码-Rails3消息队列系统 Sidekiq.zip 基于java的开发源码-Rails3消息队列系统 Sidekiq.zip ...