padrino/padrino-framework — Issue #770: Reloading a helper seems to break the require path.
Author: lighth7015
Created: 2012-01-26 19:12:49+00:00
State: open

Recently, I've been working on a website that requires the use of Resolv. This is all well and good until the helper I'm writing (which, incidentally is the one with the issue) has to be reloaded, which requires me to reload the Padrino development server.

The following is a trace-back from the exception which is generated-
DEBUG - TEMPLATE (0.0002ms) /index/index
NameError - uninitialized constant Resolv:
/usr/lib/ruby/1.9.1/rake/ext/module.rb:36:in `const_missing'
/home/robert_/padrino/multisite-fqdn/app/helpers/index_helper.rb:27:in `rescue in resolve_from_addr'
/home/robert_/padrino/multisite-fqdn/app/helpers/index_helper.rb:24:in `resolve_from_addr'
/home/robert_/padrino/multisite-fqdn/app/helpers/index_helper.rb:33:in `get_resolve_type'
/home/robert_/padrino/multisite-fqdn/app/views/index/index.slim:27:in `evaluate_source'
/usr/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:209:in `instance_eval'
/usr/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:209:in `evaluate_source'
/usr/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:144:in `cached_evaluate'
/usr/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:127:in `evaluate'
/usr/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:636:in `render'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/rendering.rb:195:in `render'
/home/robert_/padrino/multisite-fqdn/app/controllers/index.rb:23:in `block (2 levels) in '
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/routing.rb:118:in `instance_eval'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/routing.rb:118:in `block in to_proc'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/routing.rb:47:in `instance_eval'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/routing.rb:47:in `block (2 levels) in process_destination_path'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/routing.rb:47:in `each'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/routing.rb:47:in `block in process_destination_path'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/routing.rb:25:in `instance_eval'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/routing.rb:25:in `process_destination_path'
/usr/lib/ruby/gems/1.9.1/gems/http_router-0.10.2/lib/http_router/node/root.rb:114:in `block in []'
/usr/lib/ruby/gems/1.9.1/gems/http_router-0.10.2/lib/http_router/node/root.rb:104:in `catch'
/usr/lib/ruby/gems/1.9.1/gems/http_router-0.10.2/lib/http_router/node/root.rb:104:in `[]'
/usr/lib/ruby/gems/1.9.1/gems/http_router-0.10.2/lib/http_router.rb:119:in `block in call'
/usr/lib/ruby/gems/1.9.1/gems/http_router-0.10.2/lib/http_router.rb:119:in `catch'
/usr/lib/ruby/gems/1.9.1/gems/http_router-0.10.2/lib/http_router.rb:119:in `call'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/routing.rb:919:in `route!'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/application/routing.rb:909:in `dispatch!'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `block in call!'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `block in invoke'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `catch'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `invoke'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `call!'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:705:in `call'
/usr/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
/usr/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/reloader.rb:250:in `call'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/logger.rb:388:in `call'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/showexceptions.rb:21:in `call'
/usr/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
/usr/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `block in call'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1416:in `synchronize'
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `call'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/router.rb:83:in `block in call'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/router.rb:76:in `each'
/usr/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.6.b/lib/padrino-core/router.rb:76:in `call'
/usr/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

The index helper is written like so-
# Helper methods defined here can be accessed in any controller or view in the application
require "resolv"

MultisiteFqdn.helpers do
# def simple_helper_method
# ...
# end

def get_domain_root(hostname)
domain = ''

for p in hostname.split('.').reverse
domain = p + (domain.empty? ? '' : ".#{domain}")
break unless Resolv.getaddresses(domain).empty?
end

domain
end

def resolve_from_addr address

# Resolve object 'thing'
begin
Resolv.getname(address)
{ :what => "Domain Name", :addr => get_domain_root(address) }
rescue Resolv::ResolvError
{ :what => "IP Address", :addr => address }
end
end

def get_resolve_type address
resolve_from_addr address
end
end

Is there a reason for this, or is it a bug?

Thanks,
- Robert