{"action":"created","issue":{"url":"https://api.github.com/repos/nesaulov/surrealist/issues/24","repository_url":"https://api.github.com/repos/nesaulov/surrealist","labels_url":"https://api.github.com/repos/nesaulov/surrealist/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/nesaulov/surrealist/issues/24/comments","events_url":"https://api.github.com/repos/nesaulov/surrealist/issues/24/events","html_url":"https://github.com/nesaulov/surrealist/issues/24","id":264334019,"number":24,"title":"`root_key` optional argument","user":{"login":"nesaulov","id":20617394,"avatar_url":"https://avatars3.githubusercontent.com/u/20617394?v=4","gravatar_id":"","url":"https://api.github.com/users/nesaulov","html_url":"https://github.com/nesaulov","followers_url":"https://api.github.com/users/nesaulov/followers","following_url":"https://api.github.com/users/nesaulov/following{/other_user}","gists_url":"https://api.github.com/users/nesaulov/gists{/gist_id}","starred_url":"https://api.github.com/users/nesaulov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nesaulov/subscriptions","organizations_url":"https://api.github.com/users/nesaulov/orgs","repos_url":"https://api.github.com/users/nesaulov/repos","events_url":"https://api.github.com/users/nesaulov/events{/privacy}","received_events_url":"https://api.github.com/users/nesaulov/received_events","type":"User","site_admin":false},"labels":[{"id":685427640,"url":"https://api.github.com/repos/nesaulov/surrealist/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":685427642,"url":"https://api.github.com/repos/nesaulov/surrealist/labels/good%20first%20issue","name":"good first issue","color":"7057ff","default":true},{"id":708814455,"url":"https://api.github.com/repos/nesaulov/surrealist/labels/Hacktoberfest","name":"Hacktoberfest","color":"d93f0b","default":false},{"id":685427641,"url":"https://api.github.com/repos/nesaulov/surrealist/labels/help%20wanted","name":"help wanted","color":"33aa3f","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-10-10T18:41:00Z","updated_at":"2017-10-14T18:31:37Z","closed_at":null,"author_association":"OWNER","body":"Right now `Surrealist` has optional `include_root` key word argument that works like this:\r\n```ruby\r\nmodule Animal\r\n  class Cat\r\n    include Surrealist\r\n\r\n    json_schema do\r\n      { weight: String }\r\n    end\r\n\r\n    def weight\r\n      '3 kilos'\r\n    end\r\n  end\r\nend\r\n\r\nAnimal::Cat.new.surrealize(include_root: true)\r\n# => '{ \"cat\": { \"weight\": \"3 kilos\" } }'\r\n```\r\nIt takes the bottom-level class name and sets it as a root key to resulting JSON. I think we need yet another kwarg: `root:`, so that JSON can be wrapped into any key that user provides. I imagine API like this:\r\n```ruby\r\nAnimal::Cat.new.surrealize(root: :kitten)\r\n# => '{ \"kitten\": { \"weight\": \"3 kilos\" } }'\r\nAnimal::Cat.new.surrealize(root: 'kitten')\r\n# => '{ \"kitten\": { \"weight\": \"3 kilos\" } }'\r\n```\r\nIt should work without `include_root` and `include_namespaces`. \r\nAnd when both `include_root || include_namespaces` and `root` are passed, the hash that is returned from `include_root` or `include_namespaces` should be wrapped into `root`:\r\n\r\n```ruby\r\nAnimal::Cat.new.surrealize(include_root: true, root: :kitten)\r\n# => '{ \"kitten\": { \"cat\": { \"weight\": \"3 kilos\" } } }'\r\nAnimal::Cat.new.surrealize(include_namespaces: true, root: 'kitten')\r\n# => '{ \"kitten\": { \"animal\": { \"cat\": { \"weight\": \"3 kilos\" } } } }'\r\n```"},"comment":{"url":"https://api.github.com/repos/nesaulov/surrealist/issues/comments/336654566","html_url":"https://github.com/nesaulov/surrealist/issues/24#issuecomment-336654566","issue_url":"https://api.github.com/repos/nesaulov/surrealist/issues/24","id":336654566,"user":{"login":"chrisatanasian","id":2495892,"avatar_url":"https://avatars0.githubusercontent.com/u/2495892?v=4","gravatar_id":"","url":"https://api.github.com/users/chrisatanasian","html_url":"https://github.com/chrisatanasian","followers_url":"https://api.github.com/users/chrisatanasian/followers","following_url":"https://api.github.com/users/chrisatanasian/following{/other_user}","gists_url":"https://api.github.com/users/chrisatanasian/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisatanasian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisatanasian/subscriptions","organizations_url":"https://api.github.com/users/chrisatanasian/orgs","repos_url":"https://api.github.com/users/chrisatanasian/repos","events_url":"https://api.github.com/users/chrisatanasian/events{/privacy}","received_events_url":"https://api.github.com/users/chrisatanasian/received_events","type":"User","site_admin":false},"created_at":"2017-10-14T18:31:37Z","updated_at":"2017-10-14T18:31:37Z","author_association":"NONE","body":"@nesaulov Here is my PR: https://github.com/nesaulov/surrealist/pull/32/"}}
{"actor":{"display_login":"chrisatanasian"}}