Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dissecting Ruby with Ruby

Dissecting Ruby with Ruby

Dig into massive libraries with ease when you learn how to dissect ruby with ruby.

India Ruby Conf Edition.

Richard Schneeman

March 23, 2013
Tweet

More Decks by Richard Schneeman

Other Decks in Programming

Transcript

  1. Nil

  2. [ "~/projects/triage/app/controllers/pages_controller.rb:6:in `index'", "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:in "ruby/gems/actionpack-3.2.12/lib/abstract_controller/base.rb:167:in `process_act "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:in `proc "ruby/gems/actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in `block

    i "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:414:in `_run__37 "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_ca "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_pro "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callb "ruby/gems/actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:in `process "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in `proces "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:i "ruby/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `bloc "ruby/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb "ruby/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `inst "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:29:i File
  3. [ "~/projects/triage/app/controllers/pages_controller.rb:6:in `index'", "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:in "ruby/gems/actionpack-3.2.12/lib/abstract_controller/base.rb:167:in `process_act "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:in `proc "ruby/gems/actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in `block

    i "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:414:in `_run__37 "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_ca "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_pro "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callb "ruby/gems/actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:in `process "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in `proces "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:i "ruby/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `bloc "ruby/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb "ruby/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `inst "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:29:i Line Number
  4. [ "~/projects/triage/app/controllers/pages_controller.rb:6:in `index'", "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:in "ruby/gems/actionpack-3.2.12/lib/abstract_controller/base.rb:167:in `process_act "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:in `proc "ruby/gems/actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in `block

    i "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:414:in `_run__37 "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_ca "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_pro "ruby/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callb "ruby/gems/actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:in `process "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in `proces "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:i "ruby/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `bloc "ruby/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb "ruby/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `inst "ruby/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:29:i Method Name
  5. $ cat app/models/user.rb class User < ActiveRecord::Base has_many :repo_subscriptions, dependent:

    :destroy has_many :repos, :through => :repo_subscriptions scope :public, where("private is not true") alias_attribute :token, :github_access_token def self.random order("RANDOM()") end #...
  6. link_to in (rails) email templates needs a host set, but

    fails if you include http:// Problem:
  7. def link_to(*args, &block) if block_given? options = args.first || {}

    html_options = args.second link_to(capture(&block), options, html_options) else name = args[0] options = args[1] || {} html_options = args[2] html_options = convert_options_to_data_attributes(options, html_options url = url_for(options) href = html_options['href'] tag_options = tag_options(html_options) href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a end end {
  8. name = args[0] options = args[1] || {} html_options =

    args[2] html_options = convert_options_to_data_attributes(opt url = url_for(options) href = html_options['href'] tag_options = tag_options(html_options) href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escap
  9. name = args[0] options = args[1] || {} html_options =

    args[2] html_options = convert_options_to_data_attributes(opt url = url_for(options) href = html_options['href'] tag_options = tag_options(html_options) href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escap
  10. name = args[0] options = args[1] || {} html_options =

    args[2] html_options = convert_options_to_data_attributes(opt url = url_for(options) href = html_options['href'] tag_options = tag_options(html_options) href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escap
  11. name = args[0] options = args[1] || {} html_options =

    args[2] html_options = convert_options_to_data_attributes(opt puts “==============================” puts method(:url_for).source_location url = url_for(options) href = html_options['href'] tag_options = tag_options(html_options)
  12. def url_for(options = {}) options ||= {} case options when

    String options when Hash options = options.symbolize_keys.reverse_merge!(: super when :back controller.request.env["HTTP_REFERER"] || 'javasc else polymorphic_path(options) end end
  13. def url_for(options = {}) options ||= {} case options when

    String options when Hash options = options.symbolize_keys.reverse_merge!(: puts "===========================" puts self.class.ancestors super when :back controller.request.env["HTTP_REFERER"] || 'javasc else polymorphic_path(options) end end
  14. def url_for(options = {}) options ||= {} case options when

    String options when Hash options = options.symbolize_keys.reverse_merge!(: puts "===========================" puts self.class.ancestors super when :back controller.request.env["HTTP_REFERER"] || 'javasc else polymorphic_path(options) end end
  15. puts "===========================" puts self.class.ancestors [#<Class:0x007f8d0bc26ad8>, #<Module:0x007f8d0d65aaa8 #<Module:0x007f8d0a33d4e0>, ActionMailer::MailHelper ActionDispatch::Routing::RouteSet::MountedHelpers, #<Module:0x007f8d0d6bcb90>,

    ActionDispatch::Routing: ActionView::Base, Devise::OmniAuth::UrlHelpers, Devi WillPaginate::ActionView, WillPaginate::ViewHelpers, ActionView::Helpers, ActionView::Helpers::Translatio ActionView::Helpers::RecordTagHelper, ActionControll ActionView::Helpers::OutputSafetyHelper, ActionView: ActionView::Helpers::JavaScriptHelper, ActionView::H ActionView::Helpers::FormHelper, ActionView::Helpers ActionView::Helpers::DebugHelper, ActionView::Helper ActionView::Helpers::ControllerHelper, ActionView::H ActionView::Helpers::AtomFeedHelper, ActionView::Hel
  16. def url_for(options = {}) options ||= {} case options when

    String options when Hash options = options.symbolize_keys.reverse_merge!(: puts "===========================" puts self.class.ancestors super when :back controller.request.env["HTTP_REFERER"] || 'javasc else polymorphic_path(options) end end
  17. def url_for(options = {}) options ||= {} case options when

    String options when Hash options = options.symbolize_keys.reverse_merge!(:only puts "===========================" self.class.ancestors.each do |klass| next unless klass.method_defined?(:url_for) puts klass.instance_method(:url_for).source_locatio end super when :back controller.request.env["HTTP_REFERER"] || 'javascript else polymorphic_path(options)
  18. def url_for(options = {}) options ||= {} case options when

    String options when Hash options = options.symbolize_keys.reverse_merge!(:only puts "===========================" self.class.ancestors.each do |klass| next unless klass.method_defined?(:url_for) puts klass.instance_method(:url_for).source_locatio end super when :back controller.request.env["HTTP_REFERER"] || 'javascript else polymorphic_path(options)
  19. def url_for(options = {}) options ||= {} case options when

    String options when Hash options = options.symbolize_keys.reverse_merge!(:only puts "===========================" self.class.ancestors.each do |klass| next unless klass.method_defined?(:url_for) puts klass.instance_method(:url_for).source_locatio end super when :back controller.request.env["HTTP_REFERER"] || 'javascript else polymorphic_path(options)
  20. def url_for(options = {}) options ||= {} case options when

    String options when Hash options = options.symbolize_keys.reverse_merge!(:only puts "===========================" self.class.ancestors.each do |klass| next unless klass.method_defined?(:url_for) puts klass.instance_method(:url_for).source_locatio end super when :back controller.request.env["HTTP_REFERER"] || 'javascript else polymorphic_path(options)
  21. self.class.ancestors.each do |klass| next unless klass.method_defined?(:url_for) puts klass.instance_method(:url_for).source_location end ======================

    actionpack-3.2.12/lib/action_view/helpers/url_helper.rb 100 actionpack-3.2.12/lib/action_view/helpers/url_helper.rb 100 actionpack-3.2.12/lib/action_view/helpers/url_helper.rb 100 actionpack-3.2.12/lib/action_dispatch/routing/url_for.rb 143
  22. Verify Caller def url_for(options = nil) puts "===========================" puts caller.inspect

    case options when String options when nil, Hash _routes.url_for((options || {}).symbolize_keys.rev else polymorphic_url(options) end end
  23. Follow the Source def url_for(options = nil) case options when

    String options when nil, Hash puts "===========================" puts _routes.method(:url_for).source_location _routes.url_for((options || {}).symbolize_keys.rev else polymorphic_url(options) end end
  24. action_dispatch/routing/route_set.rb:572 def url_for(options) finalize! options = (options || {}).reverse_merge!(default_url_options) handle_positional_args(options)

    user, password = extract_authentication(options) path_segments = options.delete(:_path_segments) script_name = options.delete(:script_name) path = (script_name.blank? ? _generate_prefix(options) : script_name.chomp('/') path_options = options.except(*RESERVED_OPTIONS) path_options = yield(path_options) if block_given? path_addition, params = generate(path_options, path_segments || {}) path << path_addition params.merge!(options[:params] || {}) ActionDispatch::Http::URL.url_for(options.merge!({ :path => path, :params => params, :user => user, :password => password })) end