-
Notifications
You must be signed in to change notification settings - Fork 107
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
Global if/unless Procs for Conditional Field Rendering #127
Conversation
…tionality as spec helper
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.
this is a major breaking change.
What's the need for passing in a field_name
? I'm confused.
@philipqnguyen Yes, I called this out as breaking in the CHANGELOG, The need is that, since the global
Make sense? Or am I missing a way to still be able to do this without passing in the field_name? |
2 things off the top of my head:
While we have snuck in breaking changes before in 0.2.0 and 0.3.0 because technically versions that are pre-1.0.0 makes no guarantee on breaking changes. However, Blueprinter hasn't had a breaking change for a long time, and it's been very stable between 0.3.0 through 0.10.0, therefore I'm worried about surprising people with a breaking change all of a sudden. |
Yeah we can totally merge the field_name into the option if you think that's kosher. I think that's a little unexpected to a user that we'd add it to the options as options are something that the user should be defining not that we'd ad-hoc add to. I definitely get your desire to avoid this sort of breaking change though. Global if/unless procs are not fully useful without the field_name though 🤔 |
do you think we may have jumped the gun with globalizing Maybe all we needed as a solution for #124 was an |
@philipqnguyen I don't think we've jumped the gun, nor do I like the On a positive note, I have full confidence that we could move to 1.0.0 anytime and be fine adhering to semver with a bit more caution/maturity. Alternatively, you're right, it's not a 1.0 yet so we can make changes like this. If anyone needs to, they can pin their version to 0.10.0 |
end | ||
``` | ||
|
||
The field-level setting overrides the global config setting (for the field) if both are set. |
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.
Not blocking: This mention might be worth a bolding.
lib/blueprinter/configuration.rb
Outdated
attr_accessor :generator, :method, :sort_fields_by | ||
attr_accessor :generator, :if, :method, :sort_fields_by, :unless | ||
|
||
VALID_CALLABLES = %i(if unless) |
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.
Can we .freeze
this array?
VALID_CALLABLES = %i(if unless) | |
VALID_CALLABLES = %i(if unless).freeze |
lib/blueprinter/field.rb
Outdated
config = Blueprinter.configuration | ||
|
||
# Use field-level callable, or when not defined, try global callable | ||
tmp = if options.key?(option_name) |
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.
Non blocking: I know you didn't make it, but I don't like this variable name. since it's only invoked with :if
or :unless
I would be for renaming it to condition
or additional_condition
.
@@ -1,3 +1,3 @@ | |||
module Blueprinter | |||
VERSION = '0.10.0' | |||
VERSION = '0.11.0' |
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.
Pending the conversation this may become 1.0.0
Ok, I'm good with this becoming 1.0.0 =) @mcclayton @AllPurposeName |
Thanks for all the valuable feedback @AllPurposeName and @philipqnguyen. |
A release candidate branch is a great compromise. I look forward to all the breaking changes we add to it. |
lgtm |
Currently, you can conditionally render fields by setting a field-level options argument
:if
or:unless
.This PR enables the setting of a global
:if
and:unless
proc that will be used to evaluate the conditional render of all fields.The field-level setting overrides the global config setting (for the field) if both are set.
Field-level Setting
Global Config Setting
This PR also addresses making #124 easier/cleaner to accomplish