Skip to content

Mapping to subobjects #1

Description

@rhlobo

Hey,
I am begging to learn ruby and I am a little "desoriented", I hope you can help me.

I've been trying to map an attribute from class User to an attribute of an attribute of class Person, but I am unable to find out how to do it.

At the end, I want the Person json/hash to be kind of specific...

class Person
  include Virtus

  attribute :first_name, String
  # attribute :phone_numbers, Array ???
end

class User < ActiveRecord::Base
  # name
  # phone_number
end

mapper = SimpleAttributeMapper::Mapper.new({
  :name => :first_name,
  # ???
})

user = User.new(:name => "Astolfo", :phone_number => "12345678")
person = mapper.map(user, Person)
person.to_json # => {:first_name=>"Astolfo", :phone_numbers => [ { :number => "12345678" } ]

Thanks in advance!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions