No commit activity in last 3 years
No release in over 3 years
Easily track accessors on plain old ruby objects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.12
~> 5.0
~> 10.0
 Project Readme

RecordAccessors

This incredibly simple gem solves this specific issue:

It is useful for processing JSON payloads with PORO subclassing ActiveModelSerializers::Model, or any scenario where you need to track and query against the fields defined on a ruby class.

Installation

Add this line to your application's Gemfile:

gem 'record_accessors'

Usage

class ShipmentSerializer < ActiveModelSerializers::Model
  include RecordAccessors

  attr_accessor :id, :order_id

  def initialize(payload = {})
    initialize_from_attributes(payload)

    super(hash_from_attributes)
  end
end

payload = {
  id: 123,
  order_id: 'R123',
  other_field: 'this will be excluded from the serialized shipment'
}

shipment = ShipmentSerializer.new(payload)

render json: shipment