{"action":"created","comment":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/83455325","pull_request_review_id":4300398,"id":83455325,"diff_hunk":"@@ -84,38 +84,77 @@ module SupportsFeatureMixin\n     :terminate                => 'Terminate a VM'\n   }.freeze\n \n-  # Whenever this mixin is included we define all features as unsupported by default.\n-  # This way we can query for every feature\n   included do\n     QUERYABLE_FEATURES.keys.each do |feature|\n-      supports_not(feature)\n+      method_name = \"supports_#{feature}?\"\n+\n+      # defines the method on the instance\n+      define_method(method_name) do\n+        supports?(feature)\n+      end\n+\n+      # defines the method on the class\n+      define_singleton_method(method_name) do\n+        supports?(feature)\n+      end\n     end\n   end\n \n   class UnknownFeatureError < StandardError; end\n \n+  class FeatureDefinition\n+    def initialize(supported: false, block: nil, unsupported_reason: nil)\n+      @supported = supported\n+      @block = block\n+      @unsupported_reason = unsupported_reason\n+    end\n+\n+    def supported?\n+      @supported\n+    end\n+\n+    def unsupported_reason\n+      SupportsFeatureMixin.reason_or_default(@unsupported_reason) unless supported?\n+    end\n+\n+    def block\n+      @block\n+    end\n+  end\n+\n   def self.guard_queryable_feature(feature)\n     unless QUERYABLE_FEATURES.key?(feature.to_sym)\n       raise UnknownFeatureError, \"Feature ':#{feature}' is unknown to SupportsFeatureMixin.\"\n     end\n   end\n \n-  def self.reason_or_default(reason)\n+  def self.reason_or_default(reason = nil)\n     reason.present? ? reason : _(\"Feature not available/supported\")\n   end\n \n   # query instance for the reason why the feature is unsupported\n   def unsupported_reason(feature)\n     SupportsFeatureMixin.guard_queryable_feature(feature)\n     feature = feature.to_sym\n-    public_send(\"supports_#{feature}?\") unless unsupported.key?(feature)\n+    supports?(feature) unless unsupported.key?(feature)\n     unsupported[feature]\n   end\n \n   # query the instance if the feature is supported or not\n   def supports?(feature)\n     SupportsFeatureMixin.guard_queryable_feature(feature)\n-    public_send(\"supports_#{feature}?\")","path":"app/models/mixins/supports_feature_mixin.rb","position":68,"original_position":68,"commit_id":"e29c715826832ac6af513a5b984d521c078cff6d","original_commit_id":"e29c715826832ac6af513a5b984d521c078cff6d","user":{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false},"body":"do we even need the meta methods anymore?  `supports?(:feature)` seems perfectly fine.","created_at":"2016-10-14T16:22:04Z","updated_at":"2016-10-14T16:22:04Z","html_url":"https://github.com/ManageIQ/manageiq/pull/11322#discussion_r83455325","pull_request_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/11322","_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/83455325"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/11322#discussion_r83455325"},"pull_request":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/11322"}}},"pull_request":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/11322","id":85576167,"html_url":"https://github.com/ManageIQ/manageiq/pull/11322","diff_url":"https://github.com/ManageIQ/manageiq/pull/11322.diff","patch_url":"https://github.com/ManageIQ/manageiq/pull/11322.patch","issue_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/11322","number":11322,"state":"open","locked":false,"title":"refactor SupportsFeatureMixin to do less metaprogramming","user":{"login":"durandom","id":161888,"avatar_url":"https://avatars.githubusercontent.com/u/161888?v=3","gravatar_id":"","url":"https://api.github.com/users/durandom","html_url":"https://github.com/durandom","followers_url":"https://api.github.com/users/durandom/followers","following_url":"https://api.github.com/users/durandom/following{/other_user}","gists_url":"https://api.github.com/users/durandom/gists{/gist_id}","starred_url":"https://api.github.com/users/durandom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/durandom/subscriptions","organizations_url":"https://api.github.com/users/durandom/orgs","repos_url":"https://api.github.com/users/durandom/repos","events_url":"https://api.github.com/users/durandom/events{/privacy}","received_events_url":"https://api.github.com/users/durandom/received_events","type":"User","site_admin":false},"body":"**Before** SupportsFeature should not be included in modules because methods get created on inclusion time.\r\n\r\n```ruby\r\nclass Vm\r\n  include SupportsFeatureMixin\r\n  supports :foo\r\nend\r\nVm.new.supports_foo? #> true\r\n\r\nmodule Operations\r\n  extend ActiveSupport::Concern\r\n  include SupportsFeatureMixin\r\nend\r\nOperations.supports_foo? #> false\r\n\r\nclass SpecialVm < Vm\r\n  include Operations\r\nend\r\n# now SpecialVm.new.supports_foo? does not resolve to Vm.new.supports_foo? but Operations.supports_foo?\r\nSpecialVm.new.supports_foo? #> false\r\n```\r\n\r\n> I think part of the oddity is the creation of methods being inside included which isn't \"normal\" mixin behavior. I wonder if it's better to just have the methods defined directly in the SupportsFeatureMixin, then mixed in naturally, instead of dynamically creating them into the includee.\r\n\r\nI refactored the Mixin to **not** generate the `supports_feature?` methods upon calling the DSL `supports :feature` methods. The reason of doing that was to leverage rubys method lookupchain and have subclasses override default behavior of base classes.\r\n\r\nNow I store a `FeatureDefinition` into a class or module variable `supported_feature_definitions` upon calling the DSL. When asking an object `supports?(:feature)` I traverse the `ancestors` to find the first `FeatureDefinition` and use that to determine if the feature is supported or not.\r\n\r\nWhile both solutions look similar, the first one fails when `SupportsFeatureMixin` is included into a Module and the DSL methods are called on the module (like in the example above). This created methods which would hide other methods (because every feature would be unsupported by default).\r\n\r\nI think this approach makes it easier to use, because now you _can_ use the `included` block and `ActiveSupport::Concern` to forward the DSL to the included module. But you dont have to.\r\n\r\n\r\n\r\n","created_at":"2016-09-16T13:46:59Z","updated_at":"2016-10-14T16:22:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"145ae69b36d1c8d80a17044b2251560dd59709bf","assignee":{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false},"assignees":[{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false},{"login":"chrisarcand","id":2430490,"avatar_url":"https://avatars.githubusercontent.com/u/2430490?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisarcand","html_url":"https://github.com/chrisarcand","followers_url":"https://api.github.com/users/chrisarcand/followers","following_url":"https://api.github.com/users/chrisarcand/following{/other_user}","gists_url":"https://api.github.com/users/chrisarcand/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisarcand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisarcand/subscriptions","organizations_url":"https://api.github.com/users/chrisarcand/orgs","repos_url":"https://api.github.com/users/chrisarcand/repos","events_url":"https://api.github.com/users/chrisarcand/events{/privacy}","received_events_url":"https://api.github.com/users/chrisarcand/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/11322/commits","review_comments_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/11322/comments","review_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/11322/comments","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/e29c715826832ac6af513a5b984d521c078cff6d","head":{"label":"durandom:supports_feature_guard_include","ref":"supports_feature_guard_include","sha":"e29c715826832ac6af513a5b984d521c078cff6d","user":{"login":"durandom","id":161888,"avatar_url":"https://avatars.githubusercontent.com/u/161888?v=3","gravatar_id":"","url":"https://api.github.com/users/durandom","html_url":"https://github.com/durandom","followers_url":"https://api.github.com/users/durandom/followers","following_url":"https://api.github.com/users/durandom/following{/other_user}","gists_url":"https://api.github.com/users/durandom/gists{/gist_id}","starred_url":"https://api.github.com/users/durandom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/durandom/subscriptions","organizations_url":"https://api.github.com/users/durandom/orgs","repos_url":"https://api.github.com/users/durandom/repos","events_url":"https://api.github.com/users/durandom/events{/privacy}","received_events_url":"https://api.github.com/users/durandom/received_events","type":"User","site_admin":false},"repo":{"id":48989151,"name":"manageiq","full_name":"durandom/manageiq","owner":{"login":"durandom","id":161888,"avatar_url":"https://avatars.githubusercontent.com/u/161888?v=3","gravatar_id":"","url":"https://api.github.com/users/durandom","html_url":"https://github.com/durandom","followers_url":"https://api.github.com/users/durandom/followers","following_url":"https://api.github.com/users/durandom/following{/other_user}","gists_url":"https://api.github.com/users/durandom/gists{/gist_id}","starred_url":"https://api.github.com/users/durandom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/durandom/subscriptions","organizations_url":"https://api.github.com/users/durandom/orgs","repos_url":"https://api.github.com/users/durandom/repos","events_url":"https://api.github.com/users/durandom/events{/privacy}","received_events_url":"https://api.github.com/users/durandom/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/durandom/manageiq","description":"ManageIQ Cloud Management Platform","fork":true,"url":"https://api.github.com/repos/durandom/manageiq","forks_url":"https://api.github.com/repos/durandom/manageiq/forks","keys_url":"https://api.github.com/repos/durandom/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/durandom/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/durandom/manageiq/teams","hooks_url":"https://api.github.com/repos/durandom/manageiq/hooks","issue_events_url":"https://api.github.com/repos/durandom/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/durandom/manageiq/events","assignees_url":"https://api.github.com/repos/durandom/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/durandom/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/durandom/manageiq/tags","blobs_url":"https://api.github.com/repos/durandom/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/durandom/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/durandom/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/durandom/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/durandom/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/durandom/manageiq/languages","stargazers_url":"https://api.github.com/repos/durandom/manageiq/stargazers","contributors_url":"https://api.github.com/repos/durandom/manageiq/contributors","subscribers_url":"https://api.github.com/repos/durandom/manageiq/subscribers","subscription_url":"https://api.github.com/repos/durandom/manageiq/subscription","commits_url":"https://api.github.com/repos/durandom/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/durandom/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/durandom/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/durandom/manageiq/issues/comments{/number}","contents_url":"https://api.github.com/repos/durandom/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/durandom/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/durandom/manageiq/merges","archive_url":"https://api.github.com/repos/durandom/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/durandom/manageiq/downloads","issues_url":"https://api.github.com/repos/durandom/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/durandom/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/durandom/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/durandom/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/durandom/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/durandom/manageiq/releases{/id}","deployments_url":"https://api.github.com/repos/durandom/manageiq/deployments","created_at":"2016-01-04T10:05:53Z","updated_at":"2016-01-13T19:58:57Z","pushed_at":"2016-10-14T15:28:16Z","git_url":"git://github.com/durandom/manageiq.git","ssh_url":"git@github.com:durandom/manageiq.git","clone_url":"https://github.com/durandom/manageiq.git","svn_url":"https://github.com/durandom/manageiq","homepage":"manageiq.org","size":166280,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ManageIQ:master","ref":"master","sha":"b451a7711098ae1bfb0fb4bd7a47ed78c7fdb350","user":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"repo":{"id":20789757,"name":"manageiq","full_name":"ManageIQ/manageiq","owner":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ManageIQ/manageiq","description":"ManageIQ Open-Source Management Platform","fork":false,"url":"https://api.github.com/repos/ManageIQ/manageiq","forks_url":"https://api.github.com/repos/ManageIQ/manageiq/forks","keys_url":"https://api.github.com/repos/ManageIQ/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ManageIQ/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ManageIQ/manageiq/teams","hooks_url":"https://api.github.com/repos/ManageIQ/manageiq/hooks","issue_events_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/ManageIQ/manageiq/events","assignees_url":"https://api.github.com/repos/ManageIQ/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/ManageIQ/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/ManageIQ/manageiq/tags","blobs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ManageIQ/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/ManageIQ/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/ManageIQ/manageiq/languages","stargazers_url":"https://api.github.com/repos/ManageIQ/manageiq/stargazers","contributors_url":"https://api.github.com/repos/ManageIQ/manageiq/contributors","subscribers_url":"https://api.github.com/repos/ManageIQ/manageiq/subscribers","subscription_url":"https://api.github.com/repos/ManageIQ/manageiq/subscription","commits_url":"https://api.github.com/repos/ManageIQ/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/ManageIQ/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/comments{/number}","contents_url":"https://api.github.com/repos/ManageIQ/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/ManageIQ/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ManageIQ/manageiq/merges","archive_url":"https://api.github.com/repos/ManageIQ/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ManageIQ/manageiq/downloads","issues_url":"https://api.github.com/repos/ManageIQ/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/ManageIQ/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/ManageIQ/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/ManageIQ/manageiq/releases{/id}","deployments_url":"https://api.github.com/repos/ManageIQ/manageiq/deployments","created_at":"2014-06-13T02:31:26Z","updated_at":"2016-10-13T16:49:41Z","pushed_at":"2016-10-14T16:18:13Z","git_url":"git://github.com/ManageIQ/manageiq.git","ssh_url":"git@github.com:ManageIQ/manageiq.git","clone_url":"https://github.com/ManageIQ/manageiq.git","svn_url":"https://github.com/ManageIQ/manageiq","homepage":"manageiq.org","size":211766,"stargazers_count":336,"watchers_count":336,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":368,"mirror_url":null,"open_issues_count":852,"forks":368,"open_issues":852,"watchers":336,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/11322"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/11322"},"issue":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/11322"},"comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/11322/comments"},"review_comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/11322/comments"},"review_comment":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/11322/commits"},"statuses":{"href":"https://api.github.com/repos/ManageIQ/manageiq/statuses/e29c715826832ac6af513a5b984d521c078cff6d"}}}}
{"actor":{"display_login":"Fryguy"}}