{"action":"closed","issue":{"url":"https://api.github.com/repos/sinatra/sinatra-contrib/issues/165","labels_url":"https://api.github.com/repos/sinatra/sinatra-contrib/issues/165/labels{/name}","comments_url":"https://api.github.com/repos/sinatra/sinatra-contrib/issues/165/comments","events_url":"https://api.github.com/repos/sinatra/sinatra-contrib/issues/165/events","html_url":"https://github.com/sinatra/sinatra-contrib/issues/165","id":78999066,"number":165,"title":"Sinatra Reloader doesn't work well with modules","user":{"login":"gipnokote","id":213021,"avatar_url":"https://avatars.githubusercontent.com/u/213021?v=3","gravatar_id":"","url":"https://api.github.com/users/gipnokote","html_url":"https://github.com/gipnokote","followers_url":"https://api.github.com/users/gipnokote/followers","following_url":"https://api.github.com/users/gipnokote/following{/other_user}","gists_url":"https://api.github.com/users/gipnokote/gists{/gist_id}","starred_url":"https://api.github.com/users/gipnokote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gipnokote/subscriptions","organizations_url":"https://api.github.com/users/gipnokote/orgs","repos_url":"https://api.github.com/users/gipnokote/repos","events_url":"https://api.github.com/users/gipnokote/events{/privacy}","received_events_url":"https://api.github.com/users/gipnokote/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sinatra/sinatra-contrib/labels/reloader","name":"reloader","color":"DDDDDD"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-21T13:38:08Z","updated_at":"2015-05-22T23:41:17Z","closed_at":"2015-05-22T23:41:17Z","body":"When you have a Sinatra application with modules, Reloader works fine only when the \"main\" file is changed. When the file that contains the module is changed, it results in 404.\r\n\r\nLet's say we have this simple application:\r\n\r\n```ruby\r\nrequire 'sinatra/base'\r\nrequire 'sinatra/reloader'\r\n\r\nclass DevportalWeb < Sinatra::Base\r\n  configure :development do\r\n    register Sinatra::Reloader\r\n    also_reload 'app/*.rb'\r\n  end\r\n\r\n  require 'talk'\r\n  register Talk\r\nend\r\n```\r\n\r\nand it's module Talk where we have a route:\r\n\r\n```ruby\r\nmodule Talk\r\n  def self.registered(app)\r\n    app.get '/say' do\r\n      'hello'\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nWe can access '/say' and see it working, we can change the code in the main file and see it working, but when we change the code in the module, we'll see 404.\r\n\r\nAs far as I understand, this happens because reloader simply requires the changed file, but in this case it's not enough: \"register\" has to happen after that and it doesn't.\r\n\r\nIf (as an experiment) we modify (hardcode) the gem code so that 'updated?' for the main file would always be true, and it would always be treated as changed, and always reloaded, then \"register\" would always happen, and app wouldn't break on module's code change.\r\n\r\nThis proves that the problem can be solved with a certain effort, but we need to know which file is actually \"main\".\r\n\r\nI wasn't able to think of a nice way to make it work to propose a pull request. Maybe you can?"}}