レガシーなシステムからのリクエストを、新規開発しているシステムのモデルにマッピングするときに使えるかも知れません。
HashMapperはHashオブジェクトのキーと内容を、マッピング情報に従って変換するニーズがあるときに便利なGemです。
どんなの?
class ManyLevels extend HashMapper map from('/name'), to('/tag_attributes/name') map from('/properties/type'), to('/tag_attributes/type') map from('/tagid'), to('/tag_id') map from('/properties/egg'), to('/chicken') end input = { :name => 'ismael', :tagid => 1, :properties => { :type => 'BLAH', :egg => 33 } } ManyLevels.normalize(input) # outputs: { :tag_id => 1, :chicken => 33, :tag_attributes => { :name => 'ismael', :type => 'BLAH' } }
という感じで、map from('xxx'), to('yyy')
という構文でマッピングを書くことができます。
accept_nested_attributes_for
使いたいけど、フロントから来るパラメータを変えることができない、といったときに便利ですね。