Sha256: ee81b0b03f70e618d4d5b970c2e1fcaf8f83aafe63324ddaec457fe4c31aff5e

Contents?: true

Size: 864 Bytes

Versions: 19

Compression:

Stored size: 864 Bytes

Contents

module Pliny::Helpers
  module Serialize
    def self.included(base)
      base.send :extend, ClassMethods
    end

    def serialize(data, structure = :default)
      if self.class.serializer_class.nil?
        raise <<-eos.strip
No serializer has been specified for this endpoint. Please specify one with
`serializer Serializers::ModelName` in the endpoint.
        eos
      end

      self.class.serializer_class.new(structure).serialize(data)
    end

    module ClassMethods
      # Provide a way to specify endpoint serializer class.
      #
      # class Endpoints::User < Base
      #   serializer Serializers::User
      #
      #   get do
      #     encode serialize(User.all)
      #   end
      # end
      def serializer(serializer_class)
        @serializer_class = serializer_class
      end

      attr_reader :serializer_class
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
pliny-0.25.1 lib/pliny/helpers/serialize.rb
pliny-0.25.0 lib/pliny/helpers/serialize.rb
pliny-0.24.0 lib/pliny/helpers/serialize.rb
pliny-0.23.0 lib/pliny/helpers/serialize.rb
pliny-0.22.0 lib/pliny/helpers/serialize.rb
pliny-0.21.0 lib/pliny/helpers/serialize.rb
pliny-0.20.2 lib/pliny/helpers/serialize.rb
pliny-0.20.1 lib/pliny/helpers/serialize.rb
pliny-0.20.0 lib/pliny/helpers/serialize.rb
pliny-0.19.0 lib/pliny/helpers/serialize.rb
pliny-0.18.0 lib/pliny/helpers/serialize.rb
pliny-0.17.1 lib/pliny/helpers/serialize.rb
pliny-0.17.0 lib/pliny/helpers/serialize.rb
pliny-0.16.3 lib/pliny/helpers/serialize.rb
pliny-0.16.2 lib/pliny/helpers/serialize.rb
pliny-0.16.1 lib/pliny/helpers/serialize.rb
pliny-0.16.0 lib/pliny/helpers/serialize.rb
pliny-0.15.1 lib/pliny/helpers/serialize.rb
pliny-0.15.0 lib/pliny/helpers/serialize.rb