Sha256: f3cbca19d2b3896d50cba6a65236ea530ba8346c8e78a723df8ba12ff5b9983a

Contents?: true

Size: 1.18 KB

Versions: 9

Compression:

Stored size: 1.18 KB

Contents

require 'active_model_serializers'

module DataTables
  module ActiveModelSerializers
    class Adapter < ::ActiveModelSerializers::Adapter::Json
      extend ActiveSupport::Autoload
      autoload :Pagination
      autoload :Meta

      def serializable_hash(options = nil)
        options = serialization_options(options)

        serialized_hash = {
          data: ::ActiveModelSerializers::Adapter::Attributes.new(serializer, instance_options).serializable_hash(options)
        }
        serialized_hash[meta_key] = meta unless meta.blank?
        serialized_hash.merge!(pagination) unless pagination.blank?

        self.class.transform_key_casing!(serialized_hash, instance_options)
      end

      def meta_key
        instance_options.fetch(:meta_key, 'meta'.freeze)
      end

      protected

      def pagination
        Pagination.new(serializer).as_h
      end

      def meta
        {
          sql: serializer.object.to_sql
        }.merge(instance_options.fetch(:meta, {}))
        # }.merge(Meta.new(@serializer))
      end
    end
  end
end

# Register adapter manually (due to namespacing)
ActiveModelSerializers::Adapter.register(:dt, DataTables::ActiveModelSerializers::Adapter)

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
data_tables-responder-0.4.4rc1 lib/data_tables/active_model_serializers/adapter.rb
data_tables-responder-0.4.3 lib/data_tables/active_model_serializers/adapter.rb
data_tables-responder-0.5.0rc1 lib/data_tables/active_model_serializers/adapter.rb
data_tables-responder-0.4.2 lib/data_tables/active_model_serializers/adapter.rb
data_tables-responder-0.4.1 lib/data_tables/active_model_serializers/adapter.rb
data_tables-responder-0.4.0 lib/data_tables/active_model_serializers/adapter.rb
data_tables-responder-0.3.2 lib/data_tables/active_model_serializers/adapter.rb
data_tables-responder-0.3.1 lib/data_tables/active_model_serializers/adapter.rb
data_tables-responder-0.3.0 lib/data_tables/active_model_serializers/adapter.rb