plexus / yaks

Ruby library for building hypermedia APIs
http://rubygems.org/gems/yaks
MIT License
236 stars 26 forks source link

Two way mapping #11

Open plexus opened 10 years ago

plexus commented 10 years ago

Leaving this here in answer to https://twitter.com/jamesotron/status/470652904605368320 and for future reference.

Yaks maps in two steps, Model <-> Yaks::Resource <-> Message Format. The second part could be made bidirectional since it's a one-to-one mapping. The first part could be made bidirectional as long as only declarative features are used. For "dynamic" attribute the user would have to code the reverse mapping. For example this code is problematic

class PersonMapper
  attributes :full_name

  def full_name
    "#{object.first_name} #{object.last_name}"
  end
end

Two-way mapping is something I've kept at the back of my head but is not currently supported and would require quite a few changes.

plexus commented 9 years ago

For the record: we now has "readers" for HAL and JSON-API, so the JSON <--> Yaks::Resource step is bidirectional at least for those formats.