{"action":"created","issue":{"url":"https://api.github.com/repos/kernow/shortcode/issues/30","labels_url":"https://api.github.com/repos/kernow/shortcode/issues/30/labels{/name}","comments_url":"https://api.github.com/repos/kernow/shortcode/issues/30/comments","events_url":"https://api.github.com/repos/kernow/shortcode/issues/30/events","html_url":"https://github.com/kernow/shortcode/issues/30","id":76793813,"number":30,"title":"Presenters and automatic reload raises an exception","user":{"login":"sophiedeziel","id":1037105,"avatar_url":"https://avatars.githubusercontent.com/u/1037105?v=3","gravatar_id":"","url":"https://api.github.com/users/sophiedeziel","html_url":"https://github.com/sophiedeziel","followers_url":"https://api.github.com/users/sophiedeziel/followers","following_url":"https://api.github.com/users/sophiedeziel/following{/other_user}","gists_url":"https://api.github.com/users/sophiedeziel/gists{/gist_id}","starred_url":"https://api.github.com/users/sophiedeziel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sophiedeziel/subscriptions","organizations_url":"https://api.github.com/users/sophiedeziel/orgs","repos_url":"https://api.github.com/users/sophiedeziel/repos","events_url":"https://api.github.com/users/sophiedeziel/events{/privacy}","received_events_url":"https://api.github.com/users/sophiedeziel/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-05-15T17:22:20Z","updated_at":"2015-09-21T14:36:33Z","closed_at":"2015-09-19T07:55:05Z","body":"I am opening an issue to know if I should do something else in my project or if it is possible to improve the shortcode gem. \r\n\r\nI created my presenters in the app/presenters directory in my rails app to get automatic reload in development environment so I don't have to restart the server when I change something in a presenter. The presenters are registered in an initializer.\r\n\r\nHowever, when I modify a presenter, on the next load of a page using shortcode, I get that exception:\r\n\r\n```\r\nA copy of ExamplePresenter has been removed from the module tree but is still active!\r\n```\r\n\r\nI was able to fix this temporarily by registering my presenters in my controller, but I don't like the idea. \r\n\r\nThe other solution I think would be good is to change the register implementation to store string of the class name instead of the class itself. So the class can be reloaded and called over and over dynamically.\r\n\r\n```\r\ndef register(presenter)\r\n  validate presenter\r\n  [*presenter.for].each { |k| presenters[k.to_sym] = presenter.to_s } \r\nend\r\n```\r\n\r\nThen each time the class is needed, we'll have to use  ``` \"Classname\".constantize ```. Maybe we should make a getter method... \r\n\r\nI'm not 100% sure this will fix the problem, so I will be working on it. If that's not the solution, I will tell you. If it is, I will create a PR. If you have a better idea, I'd like to try it."},"comment":{"url":"https://api.github.com/repos/kernow/shortcode/issues/comments/142001405","html_url":"https://github.com/kernow/shortcode/issues/30#issuecomment-142001405","issue_url":"https://api.github.com/repos/kernow/shortcode/issues/30","id":142001405,"user":{"login":"sophiedeziel","id":1037105,"avatar_url":"https://avatars.githubusercontent.com/u/1037105?v=3","gravatar_id":"","url":"https://api.github.com/users/sophiedeziel","html_url":"https://github.com/sophiedeziel","followers_url":"https://api.github.com/users/sophiedeziel/followers","following_url":"https://api.github.com/users/sophiedeziel/following{/other_user}","gists_url":"https://api.github.com/users/sophiedeziel/gists{/gist_id}","starred_url":"https://api.github.com/users/sophiedeziel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sophiedeziel/subscriptions","organizations_url":"https://api.github.com/users/sophiedeziel/orgs","repos_url":"https://api.github.com/users/sophiedeziel/repos","events_url":"https://api.github.com/users/sophiedeziel/events{/privacy}","received_events_url":"https://api.github.com/users/sophiedeziel/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T14:36:33Z","updated_at":"2015-09-21T14:36:33Z","body":"@mtarnovan to reproduce it, change something in your presenter file. Each time the class changes, it is reloaded but the reference we keep remains the same. I'll have a look on other gems to see what strategy they use when they have to register classes and keep a reference to them.\r\n\r\nAnother solution would be to have the presenters in the `lib/` directory, but we'll have to restart our server each time we modify our presenters. "}}