Skip to content
Quick and simple mapping between Ruby classes
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


SuperMapper is a quick and simple mapper between Ruby object.
Define a mapping between attribute readers and writers and automatically convert classes.


Add this line to your application's Gemfile:

gem 'super_mapper'

And then execute:

$ bundle

Or install it yourself as:

$ gem install super_mapper


Defining mapping

Create a new Mapper instance, then start describing mapping to a specific class

mapper =

# Define a mapping from a User to a UserStruct
mapper.define_mapping User, UserStruct  do |user, user_struct|
  user_struct.first_name = user.first_name
  # Apply transformations
  user_struct.username = user.username.downcase
  # Generate new values 
  user_struct.created_at =

Apply conversions

user = User.first

# With target classes
user_struct = user, UserStruct

# With existing target objects (target is modified in place) user, user_struct

# Multiple mappings can be applied to the same target. 
# Later ones override previously set value if conflicts occur.

some_other_user_representation = context[:current_user] user, user_struct some_other_user_representation, user_struct

# +user_struct+ now has fields from both User and the other representation

If using target classes, they MUST implement a no-args constructor because new instances are created via


After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the SuperMapper project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

You can’t perform that action at this time.