{"action":"created","issue":{"url":"https://api.github.com/repos/chef/chef/issues/4674","repository_url":"https://api.github.com/repos/chef/chef","labels_url":"https://api.github.com/repos/chef/chef/issues/4674/labels{/name}","comments_url":"https://api.github.com/repos/chef/chef/issues/4674/comments","events_url":"https://api.github.com/repos/chef/chef/issues/4674/events","html_url":"https://github.com/chef/chef/pull/4674","id":139116828,"number":4674,"title":"implement use DSL method and lazy module inclusion","user":{"login":"lamont-granquist","id":454857,"avatar_url":"https://avatars.githubusercontent.com/u/454857?v=3","gravatar_id":"","url":"https://api.github.com/users/lamont-granquist","html_url":"https://github.com/lamont-granquist","followers_url":"https://api.github.com/users/lamont-granquist/followers","following_url":"https://api.github.com/users/lamont-granquist/following{/other_user}","gists_url":"https://api.github.com/users/lamont-granquist/gists{/gist_id}","starred_url":"https://api.github.com/users/lamont-granquist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lamont-granquist/subscriptions","organizations_url":"https://api.github.com/users/lamont-granquist/orgs","repos_url":"https://api.github.com/users/lamont-granquist/repos","events_url":"https://api.github.com/users/lamont-granquist/events{/privacy}","received_events_url":"https://api.github.com/users/lamont-granquist/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2016-03-07T22:42:09Z","updated_at":"2016-03-07T23:21:43Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/chef/chef/pulls/4674","html_url":"https://github.com/chef/chef/pull/4674","diff_url":"https://github.com/chef/chef/pull/4674.diff","patch_url":"https://github.com/chef/chef/pull/4674.patch"},"body":"WHAT THIS SOLVES\r\n\r\nI want a delightful way to do something similar to this:\r\n\r\n```ruby\r\nmodule MyMethods\r\n  def stuff\r\n  end\r\nend\r\nChef::Recipe.send(:include, MyMethods)\r\n```\r\n\r\nAnd get the semantics truly correct.\r\n\r\nPROBLEM 1 / SOLUTION 1 \r\n\r\n- this doesn't cover Chef::Provider::InlineResources\r\n\r\nso lets try:\r\n\r\n```ruby\r\nChef::Recipe.send(:include, MyMethods)\r\nChef::Provider::InlineResources.send(:include, MyMethods)\r\n```\r\n\r\nPROBLEM 2 / SOLUTION 2\r\n\r\n- this doesn't cover arbitrary classes that someone has mixed the FullDSL into\r\n\r\nso lets try:\r\n\r\n```ruby\r\nChef::DSL::Recipe::FullDSL.send(:include, MyMethods)\r\n```\r\n\r\nPROBLEM 3 / SOLUTION 3\r\n\r\n- That doesn't work at all because classes are patched by modules at class parsing time, they don't late-bind and you don't inherit the monkey patches.\r\n\r\nso lets try creating a `use MyModule` DSL method per #2234 and implement some tracking of modules that include the FullDSL so that we can update all of them.\r\n\r\nPROBLEM 4\r\n\r\n- The behavior of `Chef::DSL::Recipe::FullDSL.send(:include, MyMethods)` is /never/ what I want in that context, so lets just `@#$@#$` fix ruby....  And lets implement `use` on the DSL as well, because that will be significantly more pleasant, but now its just sugar around that call...\r\n\r\nAnd that's how I wound up here....."},"comment":{"url":"https://api.github.com/repos/chef/chef/issues/comments/193501007","html_url":"https://github.com/chef/chef/pull/4674#issuecomment-193501007","issue_url":"https://api.github.com/repos/chef/chef/issues/4674","id":193501007,"user":{"login":"lamont-granquist","id":454857,"avatar_url":"https://avatars.githubusercontent.com/u/454857?v=3","gravatar_id":"","url":"https://api.github.com/users/lamont-granquist","html_url":"https://github.com/lamont-granquist","followers_url":"https://api.github.com/users/lamont-granquist/followers","following_url":"https://api.github.com/users/lamont-granquist/following{/other_user}","gists_url":"https://api.github.com/users/lamont-granquist/gists{/gist_id}","starred_url":"https://api.github.com/users/lamont-granquist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lamont-granquist/subscriptions","organizations_url":"https://api.github.com/users/lamont-granquist/orgs","repos_url":"https://api.github.com/users/lamont-granquist/repos","events_url":"https://api.github.com/users/lamont-granquist/events{/privacy}","received_events_url":"https://api.github.com/users/lamont-granquist/received_events","type":"User","site_admin":false},"created_at":"2016-03-07T23:21:43Z","updated_at":"2016-03-07T23:21:43Z","body":"yeah i guess i could extract that from this problem.  thinking about it more i think `use` might better target the instance of Chef::Recipe that you're executing in, so that you have some seperability.  there's also the issue where people want to inject methods into resources to be able to use them in not_if/only_if blocks and ruby_block codeblocks.  i can see how that's all a separate concern from 'how do we globally patch the DSL' though."}}