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.

Db953d125f5cc49756edb6149f1b813e?s=128

Richard Schneeman

March 23, 2013
Tweet

Transcript

  1. 4.
  2. 6.
  3. 12.
  4. 15.
  5. 20.
  6. 32.
  7. 53.
  8. 54.

    Nil

  9. 55.
  10. 68.
  11. 71.

    [ "~/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
  12. 72.

    [ "~/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
  13. 73.

    [ "~/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
  14. 77.
  15. 84.

    $ 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 #...
  16. 90.

    link_to in (rails) email templates needs a host set, but

    fails if you include http:// Problem:
  17. 98.

    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 {
  18. 99.
  19. 100.

    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
  20. 101.

    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
  21. 102.

    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
  22. 104.
  23. 105.
  24. 108.

    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)
  25. 110.

    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
  26. 111.

    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
  27. 114.

    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
  28. 115.

    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
  29. 116.
  30. 125.

    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
  31. 126.
  32. 127.

    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)
  33. 128.

    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)
  34. 129.

    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)
  35. 130.

    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)
  36. 131.

    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
  37. 139.
  38. 140.
  39. 142.

    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
  40. 144.

    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
  41. 145.

    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
  42. 146.
  43. 152.