The simplest serialization ever.
Add this line to your application's Gemfile:
gem 'operators-serializer'
class UserSerializer < Operators::Serializer
def as_json
{
id: id,
name: name,
email: email
}
end
end
Usage in Rails controllers
class UsersController < ApplicationController
def index
@users = UserSerializer.serialize_collection(User.all)
end
def show
@user = UserSerializer.new(User.find_by(id: params[:id]))
end
end
Bug reports and pull requests are welcome on GitHub at https://github.com/operators-rb/operators-serializer.
The gem is available as open source under the terms of the MIT License.