A summary of data about the Ruby ecosystem.

https://github.com/trailblazer/representable

Maps representation documents from and to Ruby objects. Includes JSON, XML and YAML support, plain properties and compositions.
https://github.com/trailblazer/representable

Keywords

json-parser json-serialization xml-parser xml-serialization yaml

Keywords from Contributors

activerecord activejob mvc rubygem rack devise rspec mongodb-driver ruby-gem grape

Last synced: about 18 hours ago
JSON representation

Repository metadata

Maps representation documents from and to Ruby objects. Includes JSON, XML and YAML support, plain properties and compositions.

README.md

Representable

Representable maps Ruby objects to documents and back.
Build Status
Gem Version

In other words: Take an object and decorate it with a representer module. This will allow you to render a JSON, XML or YAML document from that object. But that's only half of it! You can also use representers to parse a document and create or populate an object.

Representable is helpful for all kind of mappings, rendering and parsing workflows. However, it is mostly useful in API code. Are you planning to write a real REST API with representable? Then check out the Roar gem first, save work and time and make the world a better place instead.

Full Documentation

Representable comes with a rich set of options and semantics for parsing and rendering documents. Its full documentation can be found on the Trailblazer site.

Example

What if we're writing an API for music - songs, albums, bands.

class Song < OpenStruct
end

song = Song.new(title: "Fallout", track: 1)

Defining Representations

Representations are defined using representer classes, called _decorator, or modules.

In these examples, let's use decorators

class SongRepresenter < Representable::Decorator
  include Representable::JSON

  property :title
  property :track
end

In the representer the #property method allows declaring represented attributes of the object. All the representer requires for rendering are readers on the represented object, e.g. #title and #track. When parsing, it will call setters - in our example, that'd be #title= and #track=.

Rendering

Mixing in the representer into the object adds a rendering method.

SongRepresenter.new(song).to_json
#=> {"title":"Fallout","track":1}

Parsing

It also adds support for parsing.

song = SongRepresenter.new(song).from_json(%{ {"title":"Roxanne"} })
#=> #<Song title="Roxanne", track=nil>

Note that parsing hashes per default does require string keys and does not pick up symbol keys.

Collections

Let's add a list of composers to the song representation.

class SongRepresenter < Representable::Decorator
  include Representable::JSON

  property :title
  property :track
  collection :composers
end

Surprisingly, #collection lets us define lists of objects to represent.

Song.new(title: "Fallout", composers: ["Stewart Copeland", "Sting"]).
  extend(SongRepresenter).to_json

#=> {"title":"Fallout","composers":["Stewart Copeland","Sting"]}

And again, this works both ways - in addition to the title it extracts the composers from the document, too.

Nesting

Representers can also manage compositions. Why not use an album that contains a list of songs?

class Album < OpenStruct
end

album = Album.new(name: "The Police", songs: [song, Song.new(title: "Synchronicity")])

Here comes the representer that defines the composition.

class AlbumRepresenter < Representable::Decorator
  include Representable::JSON

  property :name
  collection :songs, decorator: SongRepresenter, class: Song
end

Inline Representers

If you don't want to maintain two separate modules when nesting representations you can define the SongRepresenter inline.

class AlbumRepresenter < Representable::Decorator
  include Representable::JSON

  property :name

  collection :songs, class: Song do
    property :title
    property :track
    collection :composers
  end
end

More

Representable has many more features and can literally parse and render any kind of document to an arbitrary Ruby object graph.

Please check the official documentation for more.

Installation

The representable gem runs with all Ruby versions >= 2.4.0.
t

gem 'representable'

Dependencies

Representable does a great job with JSON, it also features support for XML, YAML and pure ruby
hashes. But Representable did not bundle dependencies for JSON and XML.

If you want to use JSON, add the following to your Gemfile:

gem 'multi_json'

If you want to use XML, add the following to your Gemfile:

gem 'nokogiri'

Copyright

Representable started as a heavily simplified fork of the ROXML gem. Big thanks to Ben Woosley for his extremely inspiring work.

  • Copyright (c) 2011-2020 Nick Sutterer apotonick@gmail.com
  • ROXML is Copyright (c) 2004-2009 Ben Woosley, Zak Mandhro and Anders Engstrom.

Representable is released under the MIT License.


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 3 days ago

Total Commits: 2,012
Total Committers: 57
Avg Commits per committer: 35.298
Development Distribution Score (DDS): 0.346

Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
Nick Sutterer a****k@g****m 1315
Ben Woosley b****y@g****m 534
Abdelkader Boudih t****e@g****m 20
Abinoam P. Marques Jr a****m@g****m 19
Anders Engström a****m@g****t 11
Zak Mandhro m****o@y****m 11
Yogesh Khater y****9@g****m 9
James Healy j****y@d****m 9
dblock d****k@d****g 6
Guilherme Cavalcanti g****i@g****m 5
Timo Schilling t****o@s****o 5
moxley m****n@h****g 3
Duane Johnson d****e@i****m 3
Alex Coles a****x@a****m 3
Daniele Orlandi d****e@o****m 3
Donald Plummer d****d@c****m 3
Rhett Sutphin r****t@d****t 3
Tim Adler m****l@t****e 3
Russ Olsen r****n@g****m 2
Raphael Sofaer r****l@j****m 2
Richard Boehme b****e@w****e 2
Chris Scharf s****e@g****m 2
Fran Worley f****s@s****k 2
Jan Dudulski j****n@d****l 2
Michał Matyas g****b@h****v 2
Shirren Premaratne s****n@m****m 2
Nikita Sokolov f****t@g****m 1
Pat Nakajima p****a@g****m 1
Philip Arndt p****t@g****m 1
Pinny Markowitz p****z@t****m 1
and 27 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 2 months ago

Total issues: 54
Total pull requests: 53
Average time to close issues: over 1 year
Average time to close pull requests: 10 months
Total issue authors: 47
Total pull request authors: 25
Average comments per issue: 3.02
Average comments per pull request: 1.64
Merged pull request: 26
Bot issues: 0
Bot pull requests: 0

Past year issues: 0
Past year pull requests: 2
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 0
Past year pull request authors: 1
Past year average comments per issue: 0
Past year average comments per pull request: 0.0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/trailblazer/representable

Top Issue Authors

  • apotonick (4)
  • skorth (2)
  • sbwoodside (2)
  • nonnenmacher (2)
  • Envek (2)
  • aceofbassgreg (1)
  • JIucToyxuu (1)
  • jestraw (1)
  • maxmeyer (1)
  • dvogel (1)
  • knguyendh (1)
  • yogeshjain999 (1)
  • kalynrobinson (1)
  • Nerian (1)
  • shjohnson (1)

Top Pull Request Authors

  • seuros (9)
  • yogeshjain999 (9)
  • myabc (8)
  • abinoam (3)
  • and0x000 (2)
  • richardboehme (2)
  • simi (2)
  • timoschilling (1)
  • QuinnWilton (1)
  • pivotal-casebook (1)
  • simonoff (1)
  • dmuneras (1)
  • Atul9 (1)
  • undergroundwebdesigns (1)
  • faucct (1)

Top Issue Labels

Top Pull Request Labels


Package metadata

gem.coop: representable

Renders and parses JSON/XML/YAML documents from and to Ruby objects. Includes plain properties, collections, nesting, coercion and more.

  • Homepage: https://github.com/trailblazer/representable/
  • Documentation: http://www.rubydoc.info/gems/representable/
  • Licenses: MIT
  • Latest release: 3.2.0 (published almost 4 years ago)
  • Last Synced: 2026-02-27T18:01:47.052Z (4 days ago)
  • Versions: 99
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 338,717,089 Total
  • Docker Downloads: 572,857,104
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.058%
    • Downloads: 0.072%
    • Docker downloads count: 0.162%
  • Maintainers (3)
debian-13: ruby-representable

  • Homepage: https://github.com/trailblazer/representable/
  • Documentation: https://packages.debian.org/trixie/ruby-representable
  • Licenses: mit
  • Latest release: 3.0.4-2 (published 19 days ago)
  • Last Synced: 2026-02-13T13:19:06.119Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.326%
    • Stargazers count: 0.636%
    • Forks count: 0.668%
rubygems.org: representable

Renders and parses JSON/XML/YAML documents from and to Ruby objects. Includes plain properties, collections, nesting, coercion and more.

  • Homepage: https://github.com/trailblazer/representable/
  • Documentation: http://www.rubydoc.info/gems/representable/
  • Licenses: MIT
  • Latest release: 3.2.0 (published almost 4 years ago)
  • Last Synced: 2026-02-28T23:00:33.290Z (3 days ago)
  • Versions: 99
  • Dependent Packages: 56
  • Dependent Repositories: 27,514
  • Downloads: 338,830,697 Total
  • Docker Downloads: 572,857,104
  • Rankings:
    • Downloads: 0.077%
    • Dependent repos count: 0.214%
    • Docker downloads count: 0.227%
    • Dependent packages count: 0.478%
    • Average: 0.958%
    • Stargazers count: 2.213%
    • Forks count: 2.536%
  • Maintainers (3)
proxy.golang.org: github.com/trailblazer/representable

ubuntu-22.04: ruby-representable

  • Homepage: https://github.com/trailblazer/representable/
  • Licenses:
  • Latest release: 3.0.4-1.1 (published 18 days ago)
  • Last Synced: 2026-02-13T13:24:35.162Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.04: ruby-representable

  • Homepage: https://github.com/trailblazer/representable/
  • Licenses:
  • Latest release: 3.0.4-1.1 (published 25 days ago)
  • Last Synced: 2026-02-06T15:56:19.932Z (25 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-10: ruby-representable

  • Homepage: https://github.com/trailblazer/representable/
  • Documentation: https://packages.debian.org/buster/ruby-representable
  • Licenses: mit
  • Latest release: 3.0.4-1 (published 20 days ago)
  • Last Synced: 2026-02-13T04:25:09.908Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.04: ruby-representable

  • Homepage: https://github.com/trailblazer/representable/
  • Licenses: mit
  • Latest release: 3.0.4-1.1 (published 20 days ago)
  • Last Synced: 2026-02-11T06:48:28.629Z (20 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.10: ruby-representable

  • Homepage: https://github.com/trailblazer/representable/
  • Licenses:
  • Latest release: 3.0.4-1.1 (published 18 days ago)
  • Last Synced: 2026-02-13T18:31:26.817Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.10: ruby-representable

  • Homepage: https://github.com/trailblazer/representable/
  • Licenses:
  • Latest release: 3.0.4-1.1ubuntu1 (published 22 days ago)
  • Last Synced: 2026-02-09T17:09:17.276Z (22 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-11: ruby-representable

  • Homepage: https://github.com/trailblazer/representable/
  • Documentation: https://packages.debian.org/bullseye/ruby-representable
  • Licenses: mit
  • Latest release: 3.0.4-1.1 (published 21 days ago)
  • Last Synced: 2026-02-13T08:24:19.737Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-20.04: ruby-representable

  • Homepage: https://github.com/trailblazer/representable/
  • Licenses:
  • Latest release: 3.0.4-1 (published 18 days ago)
  • Last Synced: 2026-02-13T07:21:44.280Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-12: ruby-representable

  • Homepage: https://github.com/trailblazer/representable/
  • Documentation: https://packages.debian.org/bookworm/ruby-representable
  • Licenses:
  • Latest release: 3.0.4-1.1 (published 19 days ago)
  • Last Synced: 2026-02-12T23:39:42.906Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:

Dependencies

.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • ruby/setup-ruby v1 composite
.github/workflows/ci_jruby.yml actions
  • actions/checkout v3 composite
  • ruby/setup-ruby v1 composite
.github/workflows/ci_legacy.yml actions
  • actions/checkout v3 composite
  • ruby/setup-ruby v1 composite
.github/workflows/ci_truffleruby.yml actions
  • actions/checkout v3 composite
  • ruby/setup-ruby v1 composite
Gemfile rubygems
  • minitest-line >= 0 development
  • multi_json >= 0 development
  • nokogiri >= 0 development
  • pry-byebug >= 0
representable.gemspec rubygems
  • dry-types >= 0 development
  • minitest >= 0 development
  • rake >= 0 development
  • test_xml >= 0.1.6 development
  • declarative < 0.1.0
  • trailblazer-option >= 0.1.1, < 0.2.0
  • uber < 0.2.0

Score: 31.973610502390024