Skip to content

Instantly share code, notes, and snippets.

@ideasasylum
Last active Dec 21, 2015
Embed
What would you like to do?
A Pry session when debugging a Figaro problem.
  1. First, you'll need the pry-stack_explorer gem.
  2. Then put <% binding.pry %> into your database.yml file.
  3. Start a rails c
  4. Pry will open when it starts loading the database.yml file
  5. Navigate up the stack until you reach the initializer loading
  6. Run initializers.tsort.collect &:name to see the order that the initialiser are being loaded.
  7. You should (hopefully) see figaro_load before activerecord.initialize_database
vagrant@cognito:/vagrant$ rails c
Frame number: 0/20
Frame type: eval
[1] pry(main)> up
Frame number: 1/20
Frame type: method
From: /home/vagrant/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/erb.rb @ line 838 ERB#result:
831: def result(b=TOPLEVEL_BINDING)
832: if @safe_level
833: proc {
834: $SAFE = @safe_level
835: eval(@src, b, (@filename || '(erb)'), 0)
836: }.call
837: else
=> 838: eval(@src, b, (@filename || '(erb)'), 0)
839: end
840: end
[2] pry(#<ERB>)> up
Frame number: 2/20
Frame type: method
From: /vagrant/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application/configuration.rb @ line 115 Rails::Application::Configuration#database_configuration:
113: def database_configuration
114: require 'erb'
=> 115: YAML::load(ERB.new(IO.read(paths["config/database"].first)).result)
116: end
[3] pry(#<Rails::Application::Configuration>)> up
Frame number: 3/20
Frame type: block
From: /vagrant/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/railtie.rb @ line 78 :
73: initializer "active_record.initialize_database" do |app|
74: ActiveSupport.on_load(:active_record) do
75: db_connection_type = "DATABASE_URL"
76: unless ENV['DATABASE_URL']
77: db_connection_type = "database.yml"
=> 78: self.configurations = app.config.database_configuration
79: end
80: Rails.logger.info "Connecting to database specified by #{db_connection_type}"
81:
82: establish_connection
83: end
[4] pry(ActiveRecord::Base)> up
Frame number: 4/20
Frame type: method
From: /vagrant/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb @ line 36 ActiveSupport.execute_hook:
32: def self.execute_hook(base, options, block)
33: if options[:yield]
34: block.call(base)
35: else
=> 36: base.instance_eval(&block)
37: end
38: end
[5] pry(ActiveSupport)> up
Frame number: 5/20
Frame type: block
From: /vagrant/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb @ line 26 ActiveSupport.on_load:
24: def self.on_load(name, options = {}, &block)
25: @loaded[name].each do |base|
=> 26: execute_hook(base, options, block)
27: end
28:
29: @load_hooks[name] << [block, options]
30: end
[6] pry(ActiveSupport)> up
Frame number: 6/20
Frame type: method
From: /vagrant/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb @ line 25 ActiveSupport.on_load:
24: def self.on_load(name, options = {}, &block)
=> 25: @loaded[name].each do |base|
26: execute_hook(base, options, block)
27: end
28:
29: @load_hooks[name] << [block, options]
30: end
[7] pry(ActiveSupport)> up
Frame number: 7/20
Frame type: block
From: /vagrant/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/railtie.rb @ line 74 :
69: end
70:
71: # This sets the database configuration from Configuration#database_configuration
72: # and then establishes the connection.
73: initializer "active_record.initialize_database" do |app|
=> 74: ActiveSupport.on_load(:active_record) do
75: db_connection_type = "DATABASE_URL"
76: unless ENV['DATABASE_URL']
77: db_connection_type = "database.yml"
78: self.configurations = app.config.database_configuration
79: end
[8] pry(#<ActiveRecord::Railtie>)> up
Frame number: 8/20
Frame type: method
From: /vagrant/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb @ line 30 Rails::Initializable::Initializer#run:
29: def run(*args)
=> 30: @context.instance_exec(*args, &block)
31: end
[9] pry(#<Rails::Initializable::Initializer>)> up
Frame number: 9/20
Frame type: block
From: /vagrant/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb @ line 55 Rails::Initializable#run_initializers:
52: def run_initializers(group=:default, *args)
53: return if instance_variable_defined?(:@ran)
54: initializers.tsort.each do |initializer|
=> 55: initializer.run(*args) if initializer.belongs_to?(group)
56: end
57: @ran = true
58: end
[10] pry(#<Cognito::Application>)> up
Frame number: 10/20
Frame type: method
From: /vagrant/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb @ line 54 Rails::Initializable#run_initializers:
52: def run_initializers(group=:default, *args)
53: return if instance_variable_defined?(:@ran)
=> 54: initializers.tsort.each do |initializer|
55: initializer.run(*args) if initializer.belongs_to?(group)
56: end
57: @ran = true
58: end
[11] pry(#<Cognito::Application>)> initializers.tsort.collect &:name
=> [:set_load_path,
:set_load_path,
:set_load_path,
:set_load_path,
:set_load_path,
:set_load_path,
:set_load_path,
:set_load_path,
:set_load_path,
:set_load_path,
:set_load_path,
:set_autoload_paths,
:set_autoload_paths,
:set_autoload_paths,
:set_autoload_paths,
:set_autoload_paths,
:set_autoload_paths,
:set_autoload_paths,
:set_autoload_paths,
:set_autoload_paths,
:set_autoload_paths,
:set_autoload_paths,
:add_routing_paths,
:add_routing_paths,
:add_routing_paths,
:add_routing_paths,
:add_routing_paths,
:add_routing_paths,
:add_routing_paths,
:add_routing_paths,
:add_routing_paths,
:add_routing_paths,
:add_routing_paths,
:add_locales,
:add_locales,
:add_locales,
:add_locales,
:add_locales,
:add_locales,
:add_locales,
:add_locales,
:add_locales,
:add_locales,
:add_locales,
:add_view_paths,
:add_view_paths,
:add_view_paths,
:add_view_paths,
:add_view_paths,
:add_view_paths,
:add_view_paths,
:add_view_paths,
:add_view_paths,
:add_view_paths,
:add_view_paths,
:load_environment_config,
:load_environment_config,
:load_environment_config,
:load_environment_config,
:load_environment_config,
:load_environment_config,
:load_environment_config,
:load_environment_config,
:load_environment_config,
:load_environment_config,
:load_environment_config,
:load_environment_hook,
:load_active_support,
:preload_frameworks,
:initialize_logger,
:initialize_cache,
:initialize_dependency_mechanism,
:bootstrap_hook,
"i18n.callbacks",
"active_support.initialize_whiny_nils",
"active_support.deprecation_behavior",
"active_support.initialize_time_zone",
"action_dispatch.configure",
"action_view.embed_authenticity_token_in_remote_forms",
"action_view.cache_asset_ids",
"action_view.javascript_expansions",
"action_view.set_configs",
"action_view.caching",
"action_controller.logger",
"action_controller.initialize_framework_caches",
"action_controller.assets_config",
"action_controller.set_configs",
"action_controller.compile_config_methods",
"active_record.initialize_timezone",
"active_record.logger",
"active_record.identity_map",
"active_record.set_configs",
"figaro_load",
"active_record.initialize_database",
"active_record.validate_explain_support",
"active_record.log_runtime",
"active_record.set_reloader_hooks",
"active_record.add_watchable_files",
"action_mailer.logger",
"action_mailer.set_configs",
"action_mailer.compile_config_methods",
"active_resource.set_configs",
"sprockets.environment",
"better_errors.configure_rails_initialization",
"less-rails.before.load_config_initializers",
:append_assets_path,
:append_assets_path,
:append_assets_path,
:append_assets_path,
:append_assets_path,
:append_assets_path,
:append_assets_path,
:append_assets_path,
:append_assets_path,
:append_assets_path,
:append_assets_path,
:prepend_helpers_path,
:prepend_helpers_path,
:prepend_helpers_path,
:prepend_helpers_path,
:prepend_helpers_path,
:prepend_helpers_path,
:prepend_helpers_path,
:prepend_helpers_path,
:prepend_helpers_path,
:prepend_helpers_path,
:prepend_helpers_path,
:load_config_initializers,
:load_config_initializers,
:load_config_initializers,
:load_config_initializers,
:load_config_initializers,
:load_config_initializers,
:load_config_initializers,
:load_config_initializers,
:load_config_initializers,
:load_config_initializers,
:load_config_initializers,
"less-rails.after.load_config_initializers",
"less-rails.after.append_assets_path",
"less-rails.setup_compression",
"apartment.init",
"carrierwave.setup_paths",
"carrierwave.active_record",
"newrelic_rpm.start_plugin",
"draper.extend_action_controller_base",
"draper.extend_action_mailer_base",
"draper.extend_active_record_base",
:after_initialize,
:engines_blank_point,
:engines_blank_point,
:engines_blank_point,
"MailsViewer precompile hook",
:engines_blank_point,
"quiet_assets",
:engines_blank_point,
:engines_blank_point,
:engines_blank_point,
"dresssed.setup",
"dresssed.less",
"dresssed.compressor",
"dresssed.will_paginate",
"dresssed.simple_form",
:engines_blank_point,
"devise.url_helpers",
"devise.omniauth",
"devise.mongoid_version_warning",
"devise.fix_routes_proxy_missing_respond_to_bug",
:engines_blank_point,
:engines_blank_point,
:engines_blank_point,
:add_generator_templates,
:ensure_autoload_once_paths_as_subset,
:add_builtin_route,
:build_middleware_stack,
:define_main_app_helper,
:add_to_prepare_blocks,
:run_prepare_callbacks,
:eager_load!,
:finisher_hook,
:set_routes_reloader_hook,
:set_clear_dependencies_hook,
:disable_dependency_loading]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment