Skip to content

Commit

Permalink
Release v0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
MoskitoHero committed Jun 14, 2024
1 parent 12d27eb commit d0dfe0e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
# Changelog

## v0.6.0 (2024-06-14)
### ✨New features
- Added the `context` argument to the serializer's `initialize` method. This allows you to pass a context hash to the serializer, which can be used to pass arguments to the serializer, that can be used with a `context` object within the serializer definition.
```ruby
class UserSerializer < Barley::Serializer
attributes :id, :name

def name
if context[:upcase]
object.name.upcase
else
object.name
end
end
end

Serializer.new(User.last, context: {upcase: true}).serializable_hash
# => { id: 1, name: "JOHN DOE" }
```
As a side effect, the context is now available in nested associations as well.
- Added the `scope` argument to the `many` method. This scope can either be a keyword referring to a named scope available on the object, or a lambda that will be called with the object as an argument. This allows you to filter the associated objects.
```ruby
class UserSerializer < Barley::Serializer
attributes :id, :name
many :posts, scope: :published do
attributes :id, :title
end
many :posts, key: :popular, scope: -> { where("views > 10_000").order(views: :desc).limit(5) } do
attributes :id, :title
end
end
```
See the README for more details.
### 📝 Documentation
- Updated the README to include the new `context` and `scope` arguments.
### 🧪 Tests
- Added tests for the `context` and `scope` arguments
### 🛠️ Chores
- Updated github actions image to v4

## v0.5.0 (2024-04-19)
### ✨New features
- Added the `with_context` method to the serializer. This method allows you to pass a context hash to the serializer, which can be used to pass arguments to the serializer, that can be used with a `context` object within the serializer definition.
Expand Down
2 changes: 1 addition & 1 deletion lib/barley/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Barley
VERSION = "0.5"
VERSION = "0.6"
end

0 comments on commit d0dfe0e

Please sign in to comment.