Sha256: 10843260a4a597f2bfcf941c871e033bcf9b0cb26d1b045e7461a2db531036f1

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require "zeitwerk"
loader = Zeitwerk::Loader.for_gem
loader.setup

# A performant and expressive solution for serializing Ruby objects into JSON, with a touch of opinionated "magic" ✨.
#
# @example Basic usage
#   # Define a data class.
#   class User
#     attr_reader :name, :email
#
#     def initialize(name:, email:)
#       @name = name
#       @email = email
#     end
#   end
#
#   # Define a serializer.
#   class UserSerializer < Transmutation::Serializer
#     attribute :name
#   end
#
#   # Create an instance of the data class.
#   user = User.new(name: "John", email: "john@example.com")
#
#   # Serialize the data class instance.
#   UserSerializer.new(user).to_json # => "{\"name\":\"John\"}"
#
# @example Within a Rails controller
#   class UsersController < ApplicationController
#     include Transmutation::Serialization
#
#     def show
#       user = User.find(params[:id])
#
#       # Automatically lookup the UserSerializer
#       # Serialize the data class instance using the UserSerializer
#       # Render the result as JSON to the client
#       render json: user # => "{\"name\":\"John\"}"
#     end
#   end
module Transmutation
  class Error < StandardError; end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
transmutation-0.3.1 lib/transmutation.rb
transmutation-0.3.0 lib/transmutation.rb
transmutation-0.2.3 lib/transmutation.rb
transmutation-0.2.2 lib/transmutation.rb
transmutation-0.2.1 lib/transmutation.rb
transmutation-0.2.0 lib/transmutation.rb