Sha256: 3894c8e23c8be19457c6b720ed5faea9e2185ca9fdcb2ed59f93230cbf12bed9
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true require "transmutation/core_ext/array" 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
transmutation-0.3.4 | lib/transmutation.rb |
transmutation-0.3.3 | lib/transmutation.rb |