Sha256: 43b3b1f0162f9960f0840ff84aa902b1861d936b6ec4120903add6fa3f61f992

Contents?: true

Size: 1022 Bytes

Versions: 1

Compression:

Stored size: 1022 Bytes

Contents

if Object.const_defined?(:MaglevRecord)
  puts "MaglevRecord is present."

  module MaglevRecord::Base
    def __basetype
      :maglevRecordBase
    end

    def to_database_view(depth, ranges = {}, params = {})
      obj = super

      if depth > 0
        index = 1

        obj[:attributes] = {}
        obj[:attributesSize] = @maglev_attributes.size

        range_from = ranges[:attributes] ? Integer(ranges[:attributes][0]) : 1
        range_to = ranges[:attributes] ? Integer(ranges[:attributes][1]) : 0

        if (params[:allElements])
          range_from = 1
          range_to = @maglev_attributes.size
        end

        @maglev_attributes.each do |k, v|
          if (index >= range_from)
            if (index > range_to)
              break
            else
              obj[:attributes][index] = [k.to_database_view(depth - 1, {}, params), v.to_database_view(depth - 1, {}, params)]
            end
          end

          index = index + 1
        end
      end

      return obj
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mdbe-0.1.0 lib/mdbe/database_views/maglev_record.rb