- Fixed the
as_json
method to comply with rails standards. It now accepts anoption
hash as an argument, which allows usage on anArray
- and therefore onActiveRecord::Relation
- as well as on a single object. Updated the documentation to reflect this change. This does not break compatibility with previous versions.
- Added type-checking to the
attributes
andattribute
methods. Now you can do:and the serializer will raise an error if the object's attribute is not of the specified type. See the README for more details.attributes id: Types::Strict::Integer, name: Types::Strict::String attribute :created_at, type: Types::Strict::Time
- Updated the README to include the new type-checking feature.
- Added YARD documentation. API documentation is available here
- Expanded Barley::Serializer and Barley::Serializable to handle optional root serialization.
User.last.as_json(root: true)
# => { user: { id: 1, name: "John Doe", email: "john.doe@example" } }
- Fix the cache key when no
updated_at
column is defined
- Also updated the relevant test cases to verify the new functionality.
- The 'as_json' method was replaced with 'serializable_hash' in the Serializer.
-
Added the ability to define associations with blocks. They can be nested all the way, so you can do:
one :group do attributes :id, :name end
many :posts do attributes :id, :title, :body one :author do attributes :name, :email one :profile, key_name: :author_profile do attributes :id, :bio end end end
-
Added the ability to define a key name on
attribute
,one
andmany
associations.attribute :created_at, key_name: :post_created_at one :author, key_name: :post_author many :comments, key_name: :post_comments do attributes :id, :body end
- Changed the cache key to use the object class name.
- Updated README and CHANGELOG
- Added tests on serializer.rb
- Reorganized the code in serializer.rb
- Updated RBS method signatures
- Initial release