{"action":"created","issue":{"url":"https://api.github.com/repos/brainspec/enumerize/issues/109","labels_url":"https://api.github.com/repos/brainspec/enumerize/issues/109/labels{/name}","comments_url":"https://api.github.com/repos/brainspec/enumerize/issues/109/comments","events_url":"https://api.github.com/repos/brainspec/enumerize/issues/109/events","html_url":"https://github.com/brainspec/enumerize/pull/109","id":19957227,"number":109,"title":"Shortcut methods to retrieve value and text of enum","user":{"login":"CyborgMaster","id":1882579,"avatar_url":"https://avatars.githubusercontent.com/u/1882579?v=3","gravatar_id":"","url":"https://api.github.com/users/CyborgMaster","html_url":"https://github.com/CyborgMaster","followers_url":"https://api.github.com/users/CyborgMaster/followers","following_url":"https://api.github.com/users/CyborgMaster/following{/other_user}","gists_url":"https://api.github.com/users/CyborgMaster/gists{/gist_id}","starred_url":"https://api.github.com/users/CyborgMaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyborgMaster/subscriptions","organizations_url":"https://api.github.com/users/CyborgMaster/orgs","repos_url":"https://api.github.com/users/CyborgMaster/repos","events_url":"https://api.github.com/users/CyborgMaster/events{/privacy}","received_events_url":"https://api.github.com/users/CyborgMaster/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2013-09-24T05:28:48Z","updated_at":"2015-02-16T20:47:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/brainspec/enumerize/pulls/109","html_url":"https://github.com/brainspec/enumerize/pull/109","diff_url":"https://github.com/brainspec/enumerize/pull/109.diff","patch_url":"https://github.com/brainspec/enumerize/pull/109.patch"},"body":"Define shortcut methods to retrieve the value and text of an enum from the class (as opposed to an instance)\r\n\r\nWith the following class definition:\r\n``` ruby \r\nclass Client < ActiveRecord::Base\r\n  extend Enumerize\r\n  enumerize :status, in: {inactive: 0, active: 1}\r\nend\r\n```\r\n\r\nYou can retrieve the values of the enum by calling:\r\n``` ruby\r\nClient.status.find_value(:active).value #=> 1\r\n```\r\nbut this is clunky and overly verbose, especially when trying to put together a sql query, etc.  \r\n\r\nThis adds two new methods to the attribute for each value:\r\n``` ruby\r\nClient.status.active #=> 1\r\nClient.status.active_text #=> 'Active'\r\n```\r\n\r\nThese are inline with the spirit of the methods available to instances and allow for more concise retrieval of enum values.\r\n\r\nLet me know if you have any questions or there is anything you would like me to change.\r\n"},"comment":{"url":"https://api.github.com/repos/brainspec/enumerize/issues/comments/74570039","html_url":"https://github.com/brainspec/enumerize/pull/109#issuecomment-74570039","issue_url":"https://api.github.com/repos/brainspec/enumerize/issues/109","id":74570039,"user":{"login":"CyborgMaster","id":1882579,"avatar_url":"https://avatars.githubusercontent.com/u/1882579?v=3","gravatar_id":"","url":"https://api.github.com/users/CyborgMaster","html_url":"https://github.com/CyborgMaster","followers_url":"https://api.github.com/users/CyborgMaster/followers","following_url":"https://api.github.com/users/CyborgMaster/following{/other_user}","gists_url":"https://api.github.com/users/CyborgMaster/gists{/gist_id}","starred_url":"https://api.github.com/users/CyborgMaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyborgMaster/subscriptions","organizations_url":"https://api.github.com/users/CyborgMaster/orgs","repos_url":"https://api.github.com/users/CyborgMaster/repos","events_url":"https://api.github.com/users/CyborgMaster/events{/privacy}","received_events_url":"https://api.github.com/users/CyborgMaster/received_events","type":"User","site_admin":false},"created_at":"2015-02-16T20:47:07Z","updated_at":"2015-02-16T20:47:07Z","body":"Sure, writing the test now.  \r\n\r\nWhat do you think about the singleton method concern you brought up earlier?  I read the issue you referenced, and it makes sense.  I do see how this could cause the same problem.  However, I don't think entire ActiveRecord objects should be serialized anyways.  They are way to complex and contain too much instance specific data that could cause problems when deserializing, such as the dirty state of the individual fields, related associations, or cached queries.  \r\n\r\nIf someone wants to serialize the state of an individual ActiveRecord object, they should serialize just the data from the database, and then pull that back into a clean ActiveRecord instance on deserialize.  "}}