Sha256: 15671f020e036a719874985ba90c55e0105562bb41b7a3f49edd39b7a552d9a3
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: true require 'delegate' require 'active_support/core_ext/string/inflections' require 'media_types/serialization/base' require 'media_types/serialization/wrapper/root_key' module MediaTypes module Serialization module Wrapper class MediaIndexWrapper < DelegateClass(Base) delegate :to_json, to: :to_hash delegate :class, to: :__getobj__ def initialize(serializer) super serializer end def to_hash { Wrapper::RootKey.new(__getobj__.class).pluralize => { '_index': auto_wrap_serializable.map(&method(:item_hash)), '_links': {} } } end alias to_h to_hash def header_links(view: current_view) return __getobj__.send(:header_links, view: view) if serializable && ::MediaTypes::Serialization.collect_links_for_index {} end private def auto_wrap_serializable Array(serializable) end def item_hash(item) __getobj__.instance_exec do set(item).send(:extract_self) end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
media_types-serialization-0.3.2 | lib/media_types/serialization/wrapper/media_index_wrapper.rb |