From f96ac5e4efa618a87d08b9a8ccaefcaf69e9737b Mon Sep 17 00:00:00 2001 From: alejandroereyes Date: Wed, 20 Sep 2023 10:02:40 -0500 Subject: [PATCH] change config to enforce_all_conditions Signed-off-by: alejandroereyes --- README.md | 4 ++-- lib/blueprinter/configuration.rb | 4 ++-- lib/blueprinter/field.rb | 2 +- spec/integrations/shared/base_render_examples.rb | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 37a3c6d8..c2613874 100644 --- a/README.md +++ b/README.md @@ -670,7 +670,7 @@ Output: Both the `field` and the global Blueprinter Configuration supports `:if` and `:unless` options that can be used to serialize fields conditionally. -By default, field-level conditions override global conditions. By enabling `roll_up_conditions`, BOTH field-level and global conditions must be met in order for the field to be serialized. +By default, field-level conditions override global conditions. By enabling `enforce_all_conditions`, BOTH field-level and global conditions must be met in order for the field to be serialized. ### Global Config Setting - if and unless @@ -678,7 +678,7 @@ By default, field-level conditions override global conditions. By enabling `roll Blueprinter.configure do |config| config.if = ->(field_name, obj, _options) { !obj[field_name].nil? } config.unless = ->(field_name, obj, _options) { obj[field_name].nil? } - config.roll_up_conditions = true + config.enforce_all_conditions = true end ``` diff --git a/lib/blueprinter/configuration.rb b/lib/blueprinter/configuration.rb index 253135a6..bf43ee4f 100644 --- a/lib/blueprinter/configuration.rb +++ b/lib/blueprinter/configuration.rb @@ -4,7 +4,7 @@ module Blueprinter class Configuration attr_accessor :association_default, :datetime_format, :deprecations, :field_default, :generator, :if, :method, :sort_fields_by, :unless, :extractor_default, :default_transformers, :custom_array_like_classes, - :roll_up_conditions + :enforce_all_conditions VALID_CALLABLES = %i[if unless].freeze @@ -21,7 +21,7 @@ def initialize @extractor_default = AutoExtractor @default_transformers = [] @custom_array_like_classes = [] - @roll_up_conditions = false + @enforce_all_conditions = false end def array_like_classes diff --git a/lib/blueprinter/field.rb b/lib/blueprinter/field.rb index eb6d3900..2a10cfc2 100644 --- a/lib/blueprinter/field.rb +++ b/lib/blueprinter/field.rb @@ -18,7 +18,7 @@ def extract(object, local_options) end def skip?(field_name, object, local_options) - if Blueprinter.configuration.roll_up_conditions + if Blueprinter.configuration.enforce_all_conditions any_global_or_field_condition_failed?(field_name, object, local_options) else return true if if_callable && !if_callable.call(field_name, object, local_options) diff --git a/spec/integrations/shared/base_render_examples.rb b/spec/integrations/shared/base_render_examples.rb index 77a2de6a..bc57089c 100644 --- a/spec/integrations/shared/base_render_examples.rb +++ b/spec/integrations/shared/base_render_examples.rb @@ -334,11 +334,11 @@ def self.unless_method(_field_name, _object, _options) end end - context 'roll_up_conditions is enabled' do + context 'enforce_all_conditions is enabled' do let(:local_options) { {x: 1, y: 2, v1: value, v2: other_value} } before do - Blueprinter.configuration.roll_up_conditions = true + Blueprinter.configuration.enforce_all_conditions = true Blueprinter.configuration.if = ->(field_name, object, local_opts) { if local_opts[:sparse_fields] local_opts[:sparse_fields].include?(field_name.to_s) @@ -349,7 +349,7 @@ def self.unless_method(_field_name, _object, _options) Blueprinter.configuration.unless = ->(_a,_b,_c) { other_value } end after do - Blueprinter.configuration.roll_up_conditions = false + Blueprinter.configuration.enforce_all_conditions = false Blueprinter.configuration.if = nil Blueprinter.configuration.unless = nil end