Sha256: 98522234a738ca1a4726cc5e5b01c92a606798b0b260b727f4ad74431ff3fdc0
Contents?: true
Size: 1.45 KB
Versions: 2
Compression:
Stored size: 1.45 KB
Contents
# ActiveSerializer Active Serializer is a simple objects to hash serializer. ## Usage Here's an example serializer: ```ruby class ContactSerializer include ActiveSerializer::SerializableObject serialization_rules do |contact, home_address, contact_emails| attributes :first_name, :last_name, contact attribute :full_name do "#{contact.first_name} #{contact.last_name}" end resource :address, home_address do |address| attributes :country, :city, :street, address end resources :emails, contact_emails do |email| attributes :email attribute :type do 'home' end end end end ``` Let's use it: ```ruby ContactSerializer.serialize(contact, home_address, contact_emails) ``` And we get a result: ```ruby { first_name: "John", last_name: "Smith", full_name: "John Smith", address: { country: "Russia", city: "Kazan", street: "Kosmonavton" }, emails: [ { email: "test@test.com", type: "home" }, { email: "test2@test.com", type: "home" } ] } ``` ## Installation Add this line to your application's Gemfile: gem 'active_serializer' And then execute: $ bundle Or install it yourself as: $ gem install active_serializer ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_serializer-0.1.1 | README.md |
active_serializer-0.1.0 | README.md |