`
ddl1st
  • 浏览: 98975 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

.irbrc rails 3 compatible

阅读更多
require 'rubygems' rescue nil
require 'wirble'
require 'pp'


# load wirble
Wirble.init
Wirble.colorize

IRB.conf[:AUTO_INDENT] = true

## method tracing

# enable tracing
def enable_trace( event_regex = /^(call|return)/, class_regex = /IRB|Wirble|RubyLex|RubyToken/ )
  puts "Enabling method tracing with event regex #{event_regex.inspect} and class exclusion regex #{class_regex.inspect}"

  set_trace_func Proc.new{|event, file, line, id, binding, classname|
    printf "[%8s] %30s %30s (%s:%-2d)\n", event, id, classname, file, line if
      event =~ event_regex and
      classname.to_s !~ class_regex
  }
  return
end

# disable tracing
def disable_trace
  puts "Disabling method tracing"

  set_trace_func nil
end

# access helper methods from the rails console
# http://errtheblog.com/post/43
def Object.method_added(method)
  return super(method) unless method == :helper
  (class<<self;self;end).send(:remove_method, :method_added)

  def helper(*helper_names)
    returning $helper_proxy ||= Object.new do |helper|
      helper_names.each { |h| helper.extend "#{h}_helper".classify.constantize }
    end
  end

  helper.instance_variable_set("@controller", ActionController::Integration::Session.new)

  def helper.method_missing(method, *args, &block)
    @controller.send(method, *args, &block) if @controller && method.to_s =~ /_path$|_url$/
  end

  helper :application rescue nil
end if ENV['RAILS_ENV']

if ENV.include?('RAILS_ENV')

  if !Object.const_defined?('RAILS_DEFAULT_LOGGER')
    require 'logger'
    Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
  end

  def sql(query)
    ActiveRecord::Base.connection.select_all(query)
  end
  
  if ENV['RAILS_ENV'] == 'test'
    require 'test/test_helper'
  end

#
# for rails 3
#
elsif !Rails.env.nil?
  if defined?(Rails) && Rails.logger
    Rails.logger =Logger.new(STDOUT)
    ActiveRecord::Base.logger = Rails.logger
  end
  if defined?(Rails) && Rails.env == 'test'
    require 'test/test_helper'
  end
else
  # nothing to do
end

def sql(query)
  ActiveRecord::Base.connection.select_all(query)
end


# watching AR do it's thing
# http://weblog.jamisbuck.org/2007/1/31/more-on-watching-activerecord
# + comment from the UnderPantsGnome
def log_to(stream, colorize=true)
  ActiveRecord::Base.logger = Logger.new(stream)
  ActiveRecord::Base.clear_active_connections!
  ActiveRecord::Base.colorize_logging = colorize
end

# annotate column names of an AR model
def show(obj)
  y(obj.send("column_names"))
end
IRB.conf[:PROMPT_MODE] = :SIMPLE
Hirb::View.enable


rails c
分享到:
评论

相关推荐

    Pragmatic.Rails.Recipes.Rails.3.Edition.Mar.2012.pdf

    - **全面覆盖 Rails 3**:Rails Recipes Rails 3 版本全面覆盖了 Rails 3 的新特性和改进之处,确保读者能够跟上框架的发展趋势。 - **实践导向**:本书采用实际案例和解决方案的形式,帮助读者快速解决问题,并且...

    [Agile.Web.Development.with.Rails]4rd英文版(清晰文字版pdf+源码)

    The fourth edition of this award-winning classic has been reorganized and refocused so it's more useful than ever before for developers new to Ruby and Rails. Rails 3 is a major release--the changes...

    Wiley.Ruby.on.Rails.Bible.Oct.2008

    根据提供的文件信息,“Wiley.Ruby.on.Rails.Bible.Oct.2008”这本书主要涉及Ruby on Rails的相关知识和技术。以下是对该书标题、描述以及部分内容中的关键知识点进行的详细解读: ### 标题:“Wiley.Ruby.on.Rails...

    Addison.Wesley.Rails.AntiPatterns.Best.Practice.Ruby.on.Rails.Refactoring

    《Rails反模式:最佳实践与Ruby on Rails重构》是一本由Chad Pytel和Tammer Saleh撰写的书籍,深入探讨了在Ruby on Rails开发过程中常见的反模式,并提供了相应的最佳实践和重构策略。本书旨在帮助开发者识别并避免...

    Apress.Beginning.Rails.3

    ### 关于《Beginning Rails 3》的关键知识点 #### 书籍基本信息 - **书名**:《Beginning Rails 3》 - **作者**:Cloves Carneiro Jr. 和 Rida Al Barazi - **出版社**:Apress - **出版日期**:2010年 - **ISBN-13...

    Addison.Wesley.RailsSpace.Building.a.Social.Networking.Website.with.Ruby.on.Rails

    ### Addison.Wesley.RailsSpace:使用Ruby on Rails构建社交网络网站 #### 一、引言 《RailsSpace:使用Ruby on Rails构建社交网络网站》是一本由Michael Hartl和Aurelius Prochazka共同撰写的书籍。本书旨在通过...

    Ruby.on.Rails.Web开发之旅

    Ruby.onRuby.on.Rails.Web开发之旅

    Rails.Angular.Postgres.and.Bootstrap.2nd.Edition

    Chapter 3. Secure the User Database with Postgres Constraints Chapter 4. Perform Fast Queries with Advanced Postgres Indexes Chapter 5. Create Clean Search Results with Bootstrap Components Chapter 6....

    Web.Services.on.Rails.

    《Web.Services.on.Rails》是一本专注于在Rails...同时,提供的`OReilly.Web.Services.on.Rails.May.2006.chm`文件可能包含了详细的技术讲解和实例,而`bookant.url`可能是书籍的在线资源链接,供读者深入学习和查阅。

    Pragmatic - Agile.Web.Development.with.Rails.4.Sep.2013.pdf

    Pragmatic - Agile.Web.Development.with.Rails.4.Sep.2013.pdf

    Pragmatic.Bookshelf.Deploying.Rails.Applications.May.2008

    Pragmatic.Bookshelf.Deploying.Rails.Applications.May.2008

    Agile.Web.Development.with.Rails.3nd.Edition.Beta.rar

    《敏捷Web开发:Rails 3版》是一本深入探讨使用Ruby on Rails进行敏捷Web开发的专业书籍,其Beta版提供了一次独特的预览学习机会。Rails是Ruby编程语言的一个强大框架,它极大地简化了Web应用程序的构建过程,尤其...

    The.Art.of.Rails.May.2008

    《The Art of Rails May 2008》是2008年出版的一本关于Rails框架的专著,聚焦于Ruby on Rails的高级技术和...书中的PDF文件“Wrox.The.Art.of.Rails.May.2008.pdf”应该是该书的电子版,对于在线学习和查阅非常方便。

    Pragmatic.Bookshelf.Rails.for.PHP.Developers

    Pragmatic.Bookshelf.Rails.for.PHP.Developers

    Pragmatic.Bookshelf.Agile.Web.Development.with.Rails.5

    - **标题**: "Pragmatic.Bookshelf.Agile.Web.Development.with.Rails.5" 该书标题清晰地传达了本书的核心主题——使用 Ruby on Rails 5 进行敏捷 Web 开发。它表明这是一本专注于介绍如何利用 Rails 框架来实现...

    Head.First.Rails中文版.2011.12

    3. **Rails生成器**:Rails提供了许多命令行工具,如`rails new`用于创建新项目,`generate`用于生成模型、控制器、迁移等,这些工具极大地提高了开发效率。 4. **MVC架构**:理解模型、视图和控制器各自的角色,...

    Beginning.Rails.3

    ### 关于《Beginning Rails 3》的关键知识点 #### 一、书籍概述 《Beginning Rails 3》是由Cloves Carneiro Jr. 和 Rida Al Barazi共同编写的关于使用Ruby on Rails框架进行Web开发的入门级教程。该书旨在帮助初学...

Global site tag (gtag.js) - Google Analytics