Sha256: ce8daf44857d7feffffadd9750d48789945ea419805bdb76ba45d58f1a8af1c6

Contents?: true

Size: 473 Bytes

Versions: 1

Compression:

Stored size: 473 Bytes

Contents

# frozen_string_literal: true

require 'oj'

module NutsJson
  class Serializer
    def initialize(resource = nil, pattern = nil)
      @resource = resource
      @pattern = pattern
    end

    def to_json(*_args)
      return Oj.dump({ key => self.send(@pattern, @resource) }, mode: :compat) unless @resource.respond_to?(:to_a)

      Oj.dump({ key => @resource.map { |data| self.send(@pattern, data) }}, mode: :compat)
    end

    def key
      :data
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nuts_json-0.1.1 lib/nuts_json/serializer.rb