-
Notifications
You must be signed in to change notification settings - Fork 144
Allow using symbols as a condition #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| require 'active_support/cache' | ||
|
|
||
| class Actor < User | ||
| attr_accessor :movies, :movie_ids | ||
| attr_accessor :movies, :movie_ids, :age, :birthplace, :show_birthplace | ||
|
|
||
| def self.fake(id = nil) | ||
| faked = super(id) | ||
| faked.movies = [] | ||
| faked.movie_ids = [] | ||
| faked.age = rand(99) | ||
| faked.birthplace = FFaker::Address.city | ||
| faked | ||
| end | ||
|
|
||
|
|
@@ -21,6 +23,8 @@ class ActorSerializer < UserSerializer | |
| set_type :actor | ||
|
|
||
| attribute :email, if: ->(_object, params) { params[:conditionals_off].nil? } | ||
| attribute :age, if: :symbol_conditionals_off | ||
| attribute :birthplace, if: :show_birthplace | ||
|
|
||
| has_many( | ||
| :played_movies, | ||
|
|
@@ -30,6 +34,14 @@ class ActorSerializer < UserSerializer | |
| ) do |object| | ||
| object.movies | ||
| end | ||
|
|
||
| def symbol_conditionals_off(_object, params) | ||
| params[:symbol_conditionals_off].nil? | ||
| end | ||
|
|
||
| def show_birthplace(object) | ||
| object.show_birthplace | ||
| end | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need both conditionals here. I think having just one (for ex. Let me know if I'm not missing anything here... |
||
| end | ||
|
|
||
| class CamelCaseActorSerializer | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need
:show_birthplacein the list of attributes, let's just keep it as a method... What do you think?