Sha256: b24cd8252239c0bf58aabf3e2c95eb3fd29afa07cc7b062da4fdb760686392fe

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

require 'active_graph/core/result'
require 'active_support/core_ext/module/attribute_accessors'

module ActiveGraph
  module Core
    module Responses
      extend ActiveSupport::Concern

      included do
        mattr_accessor :wrap_level
      end

      class_methods do
        def result_from_data(entities_data)
          rows = entities_data.map do |entity_data|
            wrap(entity_data.values)
          end

          ActiveGraph::Core::Result.new(entities_data.keys, rows)
        end

        private

        def wrap(value)
          case value
          when Neo4j::Driver::Types::Entity
            wrap_by_level(value)
          when Neo4j::Driver::Types::Path
            value
          when Hash
            value.map { |key, val| [key, wrap(val)] }.to_h
          when Enumerable
            value.map(&method(:wrap))
          else
            value
          end
        end

        def wrap_by_level(entity)
          case wrap_level
          when :core_entity
            entity
          else
            entity.wrap
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activegraph-10.0.0.pre.beta.5 lib/active_graph/core/responses.rb
activegraph-10.0.0.pre.beta.4 lib/active_graph/core/responses.rb
activegraph-10.0.0.pre.beta.3 lib/active_graph/core/responses.rb
activegraph-10.0.0.pre.beta.2 lib/active_graph/core/responses.rb
activegraph-10.0.0.pre.beta.1 lib/active_graph/core/responses.rb