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 21 hours ago
JSON representation
Repository metadata
Maps representation documents from and to Ruby objects. Includes JSON, XML and YAML support, plain properties and compositions.
- Host: GitHub
- URL: https://github.com/trailblazer/representable
- Owner: trailblazer
- License: mit
- Fork: true (Empact/roxml)
- Created: 2011-02-17T17:08:01.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2023-07-05T20:30:40.000Z (over 2 years ago)
- Last Synced: 2026-02-24T01:13:20.440Z (8 days ago)
- Topics: json-parser, json-serialization, xml-parser, xml-serialization, yaml
- Language: Ruby
- Homepage: http://trailblazer.to/2.1/docs/representable.html
- Size: 3.13 MB
- Stars: 687
- Watchers: 15
- Forks: 108
- Open Issues: 53
- Releases: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
README.md
Representable
Representable maps Ruby objects to documents and back.
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
- Name: TRAILBLAZER
- Login: trailblazer
- Email: info@trailblazer.to
- Kind: organization
- Description: The advanced business logic framework for Ruby.
- Website: https://trailblazer.to
- Location:
- Twitter: trailblazer_to
- Company:
- Icon url: https://avatars.githubusercontent.com/u/9336830?v=4
- Repositories: 58
- Last ynced at: 2023-04-09T04:55:31.151Z
- Profile URL: https://github.com/trailblazer
GitHub Events
Total
- Pull request event: 1
- Fork event: 1
- Issues event: 1
- Watch event: 4
Last Year
- Pull request event: 1
- Fork event: 1
- Watch event: 1
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 | 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:
- gnejs.net: 2
- deefa.com: 1
- dblock.org: 1
- schilling.io: 1
- househappy.org: 1
- instructure.com: 1
- alexbcoles.com: 1
- orlandi.com: 1
- cideasphere.com: 1
- detailedbalance.net: 1
- tim-adler.de: 1
- joindiaspora.com: 1
- webit.de: 1
- safetytoolbox.co.uk: 1
- dudulski.pl: 1
- higher.lv: 1
- me.com: 1
- teladoc.com: 1
- jmaicher.de: 1
- plainprograms.com: 1
- peek.com: 1
- codingzeal.com: 1
- yux.ch: 1
- tylerrick.com: 1
- tuneafish.de: 1
- salesforce.com: 1
- without-brains.net: 1
- louis.info: 1
- zertico.com: 1
- nfinney.com: 1
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
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
- Total packages: 13
-
Total downloads:
- rubygems: 677,547,786 total
- Total docker downloads: 1,145,714,208
- Total dependent packages: 56 (may contain duplicates)
- Total dependent repositories: 27,514 (may contain duplicates)
- Total versions: 299
- Total maintainers: 3
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
- Homepage:
- Documentation: https://pkg.go.dev/github.com/trailblazer/representable#section-documentation
- Licenses: mit
- Latest release: v3.2.0+incompatible (published almost 4 years ago)
- Last Synced: 2026-02-27T22:04:48.785Z (4 days ago)
- Versions: 91
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 6.508%
- Average: 6.726%
- Dependent repos count: 6.945%
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%
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 21 days ago)
- Last Synced: 2026-02-11T06:48:28.629Z (21 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%
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 19 days ago)
- Last Synced: 2026-02-13T07:21:44.280Z (19 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
- actions/checkout v3 composite
- ruby/setup-ruby v1 composite
- actions/checkout v3 composite
- ruby/setup-ruby v1 composite
- actions/checkout v3 composite
- ruby/setup-ruby v1 composite
- actions/checkout v3 composite
- ruby/setup-ruby v1 composite
- minitest-line >= 0 development
- multi_json >= 0 development
- nokogiri >= 0 development
- pry-byebug >= 0
- 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