Module: Api::RootService::RootResponse

Defined in:
app/middleware/api/root_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.each(&block) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/middleware/api/root_service.rb', line 19

def @owner.each(&block)
  ::Core::Io::Buffer.new(block) do |buffer|
    ::Core::Io::Json::Stream.new(buffer).open do |stream|
      stream.attribute('revision', 2)
      object.each do |model_in_json, endpoint|
        stream.block(model_in_json) do |nested_stream|
          nested_stream.block('actions') do |actions_stream|
            endpoint.model_handler.send(
              :actions,
              endpoint.model_handler,
              response: self, endpoint: endpoint
            ).map do |action, url|
              actions_stream.attribute(action, url)
            end
          end
        end
      end
    end
  end
  # json = Hash[
  #   object.map do |model_in_json,endpoint|
  #     [model_in_json, endpoint.model_handler.as_json(:response => self, :endpoint => endpoint, :target => endpoint.model_handler)]
  #   end +
  #   [ [ 'revision', 2 ] ]
  # ]
  # #Yajl::Encoder.new.encode(json, &block)
  # yield JSON.generate(json)
end

Instance Method Details

#services(services) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/middleware/api/root_service.rb', line 17

def services(services)
  self.object = services
  def @owner.each(&block)
    ::Core::Io::Buffer.new(block) do |buffer|
      ::Core::Io::Json::Stream.new(buffer).open do |stream|
        stream.attribute('revision', 2)
        object.each do |model_in_json, endpoint|
          stream.block(model_in_json) do |nested_stream|
            nested_stream.block('actions') do |actions_stream|
              endpoint.model_handler.send(
                :actions,
                endpoint.model_handler,
                response: self, endpoint: endpoint
              ).map do |action, url|
                actions_stream.attribute(action, url)
              end
            end
          end
        end
      end
    end
    # json = Hash[
    #   object.map do |model_in_json,endpoint|
    #     [model_in_json, endpoint.model_handler.as_json(:response => self, :endpoint => endpoint, :target => endpoint.model_handler)]
    #   end +
    #   [ [ 'revision', 2 ] ]
    # ]
    # #Yajl::Encoder.new.encode(json, &block)
    # yield JSON.generate(json)
  end
end