Sha256: 06282c743a33cc8ce80370791d0964c000a4d64c16440cb6e1862109cf597559

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

# 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

require "zeitwerk"
loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
loader.ignore("#{__dir__}/transmutation/core_ext")
loader.setup

require "transmutation/core_ext/array"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
transmutation-0.3.6 lib/transmutation.rb
transmutation-0.3.5 lib/transmutation.rb