{"action":"created","comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/comments/38900328","id":38900328,"diff_hunk":"@@ -14,9 +16,67 @@ def self.create(resource, options = {})\n         klass.new(resource, options)\n       end\n \n+      # @see ActiveModel::Serializer::Adapter.get\n       def self.adapter_class(adapter)\n-        adapter_name = adapter.to_s.classify.sub('API', 'Api')\n-        \"ActiveModel::Serializer::Adapter::#{adapter_name}\".safe_constantize\n+        ActiveModel::Serializer::Adapter.get(adapter)\n+      end\n+\n+      # Only the Adapter class has these methods.\n+      # None of the sublasses have them.\n+      class << ActiveModel::Serializer::Adapter\n+        # @return Hash<adapter_name, adapter_class>\n+        def adapter_map\n+          ADAPTER_MAP\n+        end\n+\n+        # @return Array<adapter_name>\n+        def adapters\n+          adapter_map.keys.sort\n+        end\n+\n+        # Adds an adapter 'klass' with 'name' to the 'adapter_map'\n+        # Names are stringified and underscored\n+        def register(name, klass)","path":"lib/active_model/serializer/adapter.rb","position":45,"original_position":45,"commit_id":"a13ffcff39f5783b92b69e0e5c10ba950823d22a","original_commit_id":"a13ffcff39f5783b92b69e0e5c10ba950823d22a","user":{"login":"bolshakov","id":991265,"avatar_url":"https://avatars.githubusercontent.com/u/991265?v=3","gravatar_id":"","url":"https://api.github.com/users/bolshakov","html_url":"https://github.com/bolshakov","followers_url":"https://api.github.com/users/bolshakov/followers","following_url":"https://api.github.com/users/bolshakov/following{/other_user}","gists_url":"https://api.github.com/users/bolshakov/gists{/gist_id}","starred_url":"https://api.github.com/users/bolshakov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolshakov/subscriptions","organizations_url":"https://api.github.com/users/bolshakov/orgs","repos_url":"https://api.github.com/users/bolshakov/repos","events_url":"https://api.github.com/users/bolshakov/events{/privacy}","received_events_url":"https://api.github.com/users/bolshakov/received_events","type":"User","site_admin":false},"body":"    @param [Symbol, String] name of the registered adapter\r\n    @param [Class] klass - adapter class itself\r\n    @example \r\n        AMS::Adapter.register(:my_adapter, MyAdapter)\r\n","created_at":"2015-09-08T08:22:37Z","updated_at":"2015-09-08T08:22:37Z","html_url":"https://github.com/rails-api/active_model_serializers/pull/1017#discussion_r38900328","pull_request_url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1017","_links":{"self":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/comments/38900328"},"html":{"href":"https://github.com/rails-api/active_model_serializers/pull/1017#discussion_r38900328"},"pull_request":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1017"}}},"pull_request":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1017","id":40265764,"html_url":"https://github.com/rails-api/active_model_serializers/pull/1017","diff_url":"https://github.com/rails-api/active_model_serializers/pull/1017.diff","patch_url":"https://github.com/rails-api/active_model_serializers/pull/1017.patch","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1017","number":1017,"state":"open","locked":false,"title":"Make Adapters registerable so they are not namespace-constrained","user":{"login":"bf4","id":142914,"avatar_url":"https://avatars.githubusercontent.com/u/142914?v=3","gravatar_id":"","url":"https://api.github.com/users/bf4","html_url":"https://github.com/bf4","followers_url":"https://api.github.com/users/bf4/followers","following_url":"https://api.github.com/users/bf4/following{/other_user}","gists_url":"https://api.github.com/users/bf4/gists{/gist_id}","starred_url":"https://api.github.com/users/bf4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bf4/subscriptions","organizations_url":"https://api.github.com/users/bf4/orgs","repos_url":"https://api.github.com/users/bf4/repos","events_url":"https://api.github.com/users/bf4/events{/privacy}","received_events_url":"https://api.github.com/users/bf4/received_events","type":"User","site_admin":false},"body":"Changes:\r\n\r\n- Introduce Adapter::get for use by Serializer.adapter\r\n- Move Adapter-finding logic from Adapter::adapter_class into Adapter::get\r\n- Fix circular load warning as described in https://github.com/rails-api/active_model_serializers/commit/cf6a074a1c62e3f5a30f90a0987b8cf049272953\r\n- Allowed for gem devs to use a [`Gemfile.local`](https://github.com/rails-api/active_model_serializers/pull/1017#discussion_r37602184) for gems not in the gemspec or Gemfile e.g. `pry-byebug` (which was my usecase).\r\n \r\nBackground Ref:\r\n- https://github.com/rails-api/active_model_serializers/pull/1050#issuecomment-133295789\r\n- https://github.com/rails-api/active_model_serializers/pull/1067#discussion_r37710003. \r\n- The code in this PR was my first attempt to deal with https://github.com/rails-api/active_model_serializers/issues/1006 till I realized a simpler solution.. \r\n\r\nIntroduced interfaces:\r\n\r\n- non-inherited methods\r\n```ruby\r\nActiveModel::Serializer::Adapter.adapter_map  # a Hash<adapter_name, adapter_class>\r\nActiveModel::Serializer::Adapter.adapters     # an Array<adapter_name>\r\nActiveModel::Serializer::Adapter.register(name, klass) # adds an adapter to the adapter_map\r\nActiveModel::Serializer::Adapter.get(name_or_klass)    # raises Argument error when adapter not found\r\n```\r\n\r\n- Automatically register adapters when subclassing\r\n\r\n```ruby\r\n     def self.inherited(subclass)\r\n       ActiveModel::Serializer::Adapter.register(subclass.to_s.demodulize,\r\nsubclass)\r\n     end\r\n```\r\n\r\n- Preserves subclass method `::adapter_class(adapter)`\r\n\r\n```ruby\r\n     def self.adapter_class(adapter)\r\n       ActiveModel::Serializer::Adapter.get(adapter)\r\n     end\r\n```\r\n\r\n- Serializer.adapter now uses `Adapter.get(config.adapter)` rather than have\r\nduplicate logic\r\n\r\nTODO\r\n\r\nTest\r\n- [x] ActiveModel::Serializer::Adapter.adapter_map\r\n- [x] ActiveModel::Serializer::Adapter.adapters\r\n- [x] ActiveModel::Serializer::Adapter.register(name, klass)\r\n- [x] ActiveModel::Serializer::Adapter.get(name_or_klass)\r\n- [x] ActiveModel::Serializer::Adapter::inherited\r\n- [x] ActiveModel::Serializer.adapter\r\n\r\nTO CONSIDER\r\n\r\n- [x] wrap 'finding adapter by name' logic outside of 'get' method\r\n- [x] Change exception from ArgumentError to UnknownAdapter\r\n\r\nTODO in future PR:\r\n- [ ] Change `Adapter` to module (backwards compatible public methods) and make `Adapter::Base` or `Adapter::AbstractClass` \r\n\r\nFull commit message from https://github.com/rails-api/active_model_serializers/commit/cf6a074a1c62e3f5a30f90a0987b8cf049272953\r\n\r\n<pre>\r\nEnsure inheritance hooks run\r\nI was seeing transient failures where adapters may not be registered.\r\n\r\ne.g. https://travis-ci.org/rails-api/active_model_serializers/builds/77735382\r\n\r\nSince we're using the Adapter, JsonApi, and Json classes\r\nas namespaces, some of the conventions we use for modules don't apply.\r\nBasically, we don't want to define the class anywhere besides itself.\r\nOtherwise, the inherited hooks may not run, and some adapters may not\r\nbe registered.\r\n\r\nFor example:\r\n\r\nIf we have a class Api `class Api; end`\r\nAnd Api is also used as a namespace for `Api::Product`\r\nAnd the classes are defined in different files.\r\n\r\nIn one file:\r\n\r\n```ruby\r\nclass Api\r\n  autoload :Product\r\n  def self.inherited(subclass)\r\n    puts\r\n    p [:inherited, subclass.name]\r\n    puts\r\n  end\r\nend\r\n```\r\n\r\nAnd in another:\r\n\r\n```ruby\r\nclass Api\r\n  class Product < Api\r\n    def sell_sell_sell!\r\n      # TODO: sell\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nIf we load the Api class file first, the inherited hook will be defined on the class\r\nso that when we load the Api::Product class, we'll see the output:\r\n\r\n```plain\r\n[ :inherited, Api::Product]\r\n```\r\n\r\nHowever, if we load the Api::Product class first, since it defines the `Api` class\r\nand then inherited from it, the Api file was never loaded, the hook never defined,\r\nand thus never run.\r\n\r\nBy defining the class as `class Api::Product < Api` We ensure the the Api class\r\nMUST be defined, and thus, the hook will be defined and run and so sunshine and unicorns.\r\n\r\nAppendix:\r\n\r\nThe below would work, but triggers a circular reference warning.\r\nIt's also not recommended to mix require with autoload.\r\n\r\n```ruby\r\nrequire 'api'\r\nclass Api\r\n  class Product < Api\r\n    def sell_sell_sell!\r\n      # TODO: sell\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nThis failure scenario was introduced by removing the circular reference warnings in\r\n#1067\r\n</pre>","created_at":"2015-07-17T19:54:57Z","updated_at":"2015-09-08T08:22:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"39b93d31b4b4aa279e90db50c91888aa618ddfcb","assignee":{"login":"joaomdmoura","id":667063,"avatar_url":"https://avatars.githubusercontent.com/u/667063?v=3","gravatar_id":"","url":"https://api.github.com/users/joaomdmoura","html_url":"https://github.com/joaomdmoura","followers_url":"https://api.github.com/users/joaomdmoura/followers","following_url":"https://api.github.com/users/joaomdmoura/following{/other_user}","gists_url":"https://api.github.com/users/joaomdmoura/gists{/gist_id}","starred_url":"https://api.github.com/users/joaomdmoura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joaomdmoura/subscriptions","organizations_url":"https://api.github.com/users/joaomdmoura/orgs","repos_url":"https://api.github.com/users/joaomdmoura/repos","events_url":"https://api.github.com/users/joaomdmoura/events{/privacy}","received_events_url":"https://api.github.com/users/joaomdmoura/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1017/commits","review_comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1017/comments","review_comment_url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1017/comments","statuses_url":"https://api.github.com/repos/rails-api/active_model_serializers/statuses/a13ffcff39f5783b92b69e0e5c10ba950823d22a","head":{"label":"bf4:registerable_adapters","ref":"registerable_adapters","sha":"a13ffcff39f5783b92b69e0e5c10ba950823d22a","user":{"login":"bf4","id":142914,"avatar_url":"https://avatars.githubusercontent.com/u/142914?v=3","gravatar_id":"","url":"https://api.github.com/users/bf4","html_url":"https://github.com/bf4","followers_url":"https://api.github.com/users/bf4/followers","following_url":"https://api.github.com/users/bf4/following{/other_user}","gists_url":"https://api.github.com/users/bf4/gists{/gist_id}","starred_url":"https://api.github.com/users/bf4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bf4/subscriptions","organizations_url":"https://api.github.com/users/bf4/orgs","repos_url":"https://api.github.com/users/bf4/repos","events_url":"https://api.github.com/users/bf4/events{/privacy}","received_events_url":"https://api.github.com/users/bf4/received_events","type":"User","site_admin":false},"repo":{"id":31333715,"name":"active_model_serializers","full_name":"bf4/active_model_serializers","owner":{"login":"bf4","id":142914,"avatar_url":"https://avatars.githubusercontent.com/u/142914?v=3","gravatar_id":"","url":"https://api.github.com/users/bf4","html_url":"https://github.com/bf4","followers_url":"https://api.github.com/users/bf4/followers","following_url":"https://api.github.com/users/bf4/following{/other_user}","gists_url":"https://api.github.com/users/bf4/gists{/gist_id}","starred_url":"https://api.github.com/users/bf4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bf4/subscriptions","organizations_url":"https://api.github.com/users/bf4/orgs","repos_url":"https://api.github.com/users/bf4/repos","events_url":"https://api.github.com/users/bf4/events{/privacy}","received_events_url":"https://api.github.com/users/bf4/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bf4/active_model_serializers","description":"ActiveModel::Serializer implementation and Rails hooks","fork":true,"url":"https://api.github.com/repos/bf4/active_model_serializers","forks_url":"https://api.github.com/repos/bf4/active_model_serializers/forks","keys_url":"https://api.github.com/repos/bf4/active_model_serializers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bf4/active_model_serializers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bf4/active_model_serializers/teams","hooks_url":"https://api.github.com/repos/bf4/active_model_serializers/hooks","issue_events_url":"https://api.github.com/repos/bf4/active_model_serializers/issues/events{/number}","events_url":"https://api.github.com/repos/bf4/active_model_serializers/events","assignees_url":"https://api.github.com/repos/bf4/active_model_serializers/assignees{/user}","branches_url":"https://api.github.com/repos/bf4/active_model_serializers/branches{/branch}","tags_url":"https://api.github.com/repos/bf4/active_model_serializers/tags","blobs_url":"https://api.github.com/repos/bf4/active_model_serializers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bf4/active_model_serializers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bf4/active_model_serializers/git/refs{/sha}","trees_url":"https://api.github.com/repos/bf4/active_model_serializers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bf4/active_model_serializers/statuses/{sha}","languages_url":"https://api.github.com/repos/bf4/active_model_serializers/languages","stargazers_url":"https://api.github.com/repos/bf4/active_model_serializers/stargazers","contributors_url":"https://api.github.com/repos/bf4/active_model_serializers/contributors","subscribers_url":"https://api.github.com/repos/bf4/active_model_serializers/subscribers","subscription_url":"https://api.github.com/repos/bf4/active_model_serializers/subscription","commits_url":"https://api.github.com/repos/bf4/active_model_serializers/commits{/sha}","git_commits_url":"https://api.github.com/repos/bf4/active_model_serializers/git/commits{/sha}","comments_url":"https://api.github.com/repos/bf4/active_model_serializers/comments{/number}","issue_comment_url":"https://api.github.com/repos/bf4/active_model_serializers/issues/comments{/number}","contents_url":"https://api.github.com/repos/bf4/active_model_serializers/contents/{+path}","compare_url":"https://api.github.com/repos/bf4/active_model_serializers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bf4/active_model_serializers/merges","archive_url":"https://api.github.com/repos/bf4/active_model_serializers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bf4/active_model_serializers/downloads","issues_url":"https://api.github.com/repos/bf4/active_model_serializers/issues{/number}","pulls_url":"https://api.github.com/repos/bf4/active_model_serializers/pulls{/number}","milestones_url":"https://api.github.com/repos/bf4/active_model_serializers/milestones{/number}","notifications_url":"https://api.github.com/repos/bf4/active_model_serializers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bf4/active_model_serializers/labels{/name}","releases_url":"https://api.github.com/repos/bf4/active_model_serializers/releases{/id}","created_at":"2015-02-25T20:15:49Z","updated_at":"2015-02-25T20:15:50Z","pushed_at":"2015-09-07T22:23:33Z","git_url":"git://github.com/bf4/active_model_serializers.git","ssh_url":"git@github.com:bf4/active_model_serializers.git","clone_url":"https://github.com/bf4/active_model_serializers.git","svn_url":"https://github.com/bf4/active_model_serializers","homepage":"","size":1871,"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":"rails-api:master","ref":"master","sha":"f2279946b6e65636c6e47976ed8dc7c4b31eb438","user":{"login":"rails-api","id":2820360,"avatar_url":"https://avatars.githubusercontent.com/u/2820360?v=3","gravatar_id":"","url":"https://api.github.com/users/rails-api","html_url":"https://github.com/rails-api","followers_url":"https://api.github.com/users/rails-api/followers","following_url":"https://api.github.com/users/rails-api/following{/other_user}","gists_url":"https://api.github.com/users/rails-api/gists{/gist_id}","starred_url":"https://api.github.com/users/rails-api/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails-api/subscriptions","organizations_url":"https://api.github.com/users/rails-api/orgs","repos_url":"https://api.github.com/users/rails-api/repos","events_url":"https://api.github.com/users/rails-api/events{/privacy}","received_events_url":"https://api.github.com/users/rails-api/received_events","type":"Organization","site_admin":false},"repo":{"id":2889230,"name":"active_model_serializers","full_name":"rails-api/active_model_serializers","owner":{"login":"rails-api","id":2820360,"avatar_url":"https://avatars.githubusercontent.com/u/2820360?v=3","gravatar_id":"","url":"https://api.github.com/users/rails-api","html_url":"https://github.com/rails-api","followers_url":"https://api.github.com/users/rails-api/followers","following_url":"https://api.github.com/users/rails-api/following{/other_user}","gists_url":"https://api.github.com/users/rails-api/gists{/gist_id}","starred_url":"https://api.github.com/users/rails-api/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails-api/subscriptions","organizations_url":"https://api.github.com/users/rails-api/orgs","repos_url":"https://api.github.com/users/rails-api/repos","events_url":"https://api.github.com/users/rails-api/events{/privacy}","received_events_url":"https://api.github.com/users/rails-api/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails-api/active_model_serializers","description":"ActiveModel::Serializer implementation and Rails hooks","fork":false,"url":"https://api.github.com/repos/rails-api/active_model_serializers","forks_url":"https://api.github.com/repos/rails-api/active_model_serializers/forks","keys_url":"https://api.github.com/repos/rails-api/active_model_serializers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails-api/active_model_serializers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails-api/active_model_serializers/teams","hooks_url":"https://api.github.com/repos/rails-api/active_model_serializers/hooks","issue_events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/events{/number}","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/events","assignees_url":"https://api.github.com/repos/rails-api/active_model_serializers/assignees{/user}","branches_url":"https://api.github.com/repos/rails-api/active_model_serializers/branches{/branch}","tags_url":"https://api.github.com/repos/rails-api/active_model_serializers/tags","blobs_url":"https://api.github.com/repos/rails-api/active_model_serializers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails-api/active_model_serializers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails-api/active_model_serializers/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails-api/active_model_serializers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails-api/active_model_serializers/statuses/{sha}","languages_url":"https://api.github.com/repos/rails-api/active_model_serializers/languages","stargazers_url":"https://api.github.com/repos/rails-api/active_model_serializers/stargazers","contributors_url":"https://api.github.com/repos/rails-api/active_model_serializers/contributors","subscribers_url":"https://api.github.com/repos/rails-api/active_model_serializers/subscribers","subscription_url":"https://api.github.com/repos/rails-api/active_model_serializers/subscription","commits_url":"https://api.github.com/repos/rails-api/active_model_serializers/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails-api/active_model_serializers/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments{/number}","contents_url":"https://api.github.com/repos/rails-api/active_model_serializers/contents/{+path}","compare_url":"https://api.github.com/repos/rails-api/active_model_serializers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails-api/active_model_serializers/merges","archive_url":"https://api.github.com/repos/rails-api/active_model_serializers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails-api/active_model_serializers/downloads","issues_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues{/number}","pulls_url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls{/number}","milestones_url":"https://api.github.com/repos/rails-api/active_model_serializers/milestones{/number}","notifications_url":"https://api.github.com/repos/rails-api/active_model_serializers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/labels{/name}","releases_url":"https://api.github.com/repos/rails-api/active_model_serializers/releases{/id}","created_at":"2011-12-01T06:39:26Z","updated_at":"2015-09-08T00:41:37Z","pushed_at":"2015-09-07T22:23:33Z","git_url":"git://github.com/rails-api/active_model_serializers.git","ssh_url":"git@github.com:rails-api/active_model_serializers.git","clone_url":"https://github.com/rails-api/active_model_serializers.git","svn_url":"https://github.com/rails-api/active_model_serializers","homepage":"","size":5946,"stargazers_count":2945,"watchers_count":2945,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":672,"mirror_url":null,"open_issues_count":156,"forks":672,"open_issues":156,"watchers":2945,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1017"},"html":{"href":"https://github.com/rails-api/active_model_serializers/pull/1017"},"issue":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1017"},"comments":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1017/comments"},"review_comments":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1017/comments"},"review_comment":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1017/commits"},"statuses":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/statuses/a13ffcff39f5783b92b69e0e5c10ba950823d22a"}}}}