Sha256: 537ec3b990584703db0f7c74f9768d5ad48434b61598049f1ad343da5f6e517c

Contents?: true

Size: 488 Bytes

Versions: 7

Compression:

Stored size: 488 Bytes

Contents

# frozen_string_literal: true

module ONEAccess
  module Serializable
    def represented_by(representer_class)
      @representer_class = representer_class
    end

    def from_json(json)
      if collection?
        collection = []
        @representer_class.new(collection).from_json(json)
        collection
      else
        obj = new
        @representer_class.new(obj).from_json(json)
        obj
      end
    end

    private

    def collection?
      false
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
oneaccess-1.3.1 lib/oneaccess/serializable.rb
oneaccess-1.3.0 lib/oneaccess/serializable.rb
oneaccess-1.2.0 lib/oneaccess/serializable.rb
oneaccess-1.1.0 lib/oneaccess/serializable.rb
oneaccess-1.0.1 lib/oneaccess/serializable.rb
oneaccess-1.0.0 lib/oneaccess/serializable.rb
oneaccess-0.5.0 lib/oneaccess/serializable.rb