GitHub PullRequestReviewCommentEvent at 2014-01-28 21:20:19
Repository: crichton
Actor: sheavalentine-mdsol
Payload: {"comment":{"url":"https://api.github.com/repos/mdsol/crichton/pulls/comments/9245144","id":9245144,"diff_hunk":"@@ -0,0 +1,234 @@\n+require 'crichton/representor/serializer'\n+require \"json\"\n+\n+class ::Hash\n+  def deep_merge(other)\n+    merger = ->(key, v1, v2) { \n+      Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2\n+    }\n+    self.merge(other, &merger)\n+  end\n+end\n+\n+module Crichton\n+  module Representor\n+    ##\n+    # Manages the serialization of a Crichton::Representor to an application/hale+json media-type.\n+    class HaleJsonSerializer < Serializer\n+      media_types hale_json: %w(application/hale+json)\n+\n+      ##\n+      # Returns a ruby object representing a HALe serialization.\n+      #\n+      # @param [Hash] options Optional configurations.\n+      #\n+      # @return [Hash] The built representation.\n+      def as_media_type(options = {})\n+        options ||= {}\n+        halelets = []\n+        halelets += [get_semantic_data(options)]\n+        halelets += [get_data(@object.each_transition(options), relations)]\n+        halelets += [get_data(@object.metadata_links(options), links)]\n+        base_object = halelets.reduce { |x,y| x.deep_merge(y)}\n+        ret = add_embedded(base_object, options)\n+        ret\n+      end\n+\n+      ##\n+      # Returns a json object representing a HALe serialization.\n+      #\n+      # @param [Hash] options Optional configurations.\n+      #\n+      # @return [Hash] The built representation.\n+      def to_media_type(options)\n+        haledoc = as_media_type(options)\n+        haledoc.to_json\n+      end\n+\n+      private\n+\n+      def semantic_map(sem)\n+        semantics = {\n+          select: ->(tn, x) {construct_form_semantic(tn, x, \"text\")}, #No way in Crichton to distinguis [Int] and [String]\n+          search: ->(tn, x) {construct_form_semantic(tn, x, \"text\")},\n+          text: ->(tn, x) {construct_form_semantic(tn, x, \"text\")},\n+          boolean: ->(tn, x) {construct_form_semantic(tn, x, \"bool\")}, #a Server should accept ?cat&dog or ?cat=cat&dog=dog\n+          number: ->(tn, x) {construct_form_semantic(tn, x, \"number\")},\n+          email: ->(tn, x) {construct_form_semantic(tn, x, \"text\")},     \n+          tel: ->(tn, x) {construct_form_semantic(tn, x, \"text\")}, \n+          datetime: ->(tn, x) {construct_form_semantic(tn, x, \"text\")}, \n+          time: ->(tn, x) {construct_form_semantic(tn, x, \"text\")}, \n+          date: ->(tn, x) {construct_form_semantic(tn, x, \"text\")}, \n+          month: ->(tn, x) {construct_form_semantic(tn, x, \"text\")}, \n+          week: ->(tn, x) {construct_form_semantic(tn, x, \"text\")}, \n+          :\"datetime-local\" => ->(tn, x) {construct_form_semantic(tn, x, \"text\")}\n+        }","path":"lib/crichton/representor/serializers/hale_json.rb","position":65,"original_position":65,"commit_id":"31e94d258a3c71df255971c60b7c59666f75531b","original_commit_id":"31e94d258a3c71df255971c60b7c59666f75531b","user":{"login":"sheavalentine-mdsol","id":5214853,"avatar_url":"https://gravatar.com/avatar/170b8c89b905951e6ab9caca2896d96e?d=https%3A%2F%2Fidenticons.github.com%2Fa98d0f451dbc845355dca091ec88f1c6.png&r=x","gravatar_id":"170b8c89b905951e6ab9caca2896d96e","url":"https://api.github.com/users/sheavalentine-mdsol","html_url":"https://github.com/sheavalentine-mdsol","followers_url":"https://api.github.com/users/sheavalentine-mdsol/followers","following_url":"https://api.github.com/users/sheavalentine-mdsol/following{/other_user}","gists_url":"https://api.github.com/users/sheavalentine-mdsol/gists{/gist_id}","starred_url":"https://api.github.com/users/sheavalentine-mdsol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sheavalentine-mdsol/subscriptions","organizations_url":"https://api.github.com/users/sheavalentine-mdsol/orgs","repos_url":"https://api.github.com/users/sheavalentine-mdsol/repos","events_url":"https://api.github.com/users/sheavalentine-mdsol/events{/privacy}","received_events_url":"https://api.github.com/users/sheavalentine-mdsol/received_events","type":"User","site_admin":false},"body":"This needs to include constraint information that's since it's reducing type information.","created_at":"2014-01-28T21:20:19Z","updated_at":"2014-01-28T21:20:19Z","html_url":"https://github.com/mdsol/crichton/pull/112#discussion_r9245144","pull_request_url":"https://api.github.com/repos/mdsol/crichton/pulls/112","_links":{"self":{"href":"https://api.github.com/repos/mdsol/crichton/pulls/comments/9245144"},"html":{"href":"https://github.com/mdsol/crichton/pull/112#discussion_r9245144"},"pull_request":{"href":"https://api.github.com/repos/mdsol/crichton/pulls/112"}}}}