From 6dd4924788a2778c03b40d78563d71c0a17fc0b4 Mon Sep 17 00:00:00 2001 From: Jordan Hollinger Date: Mon, 15 Jul 2024 13:32:56 -0400 Subject: [PATCH] Add options for things that don't make sense as extension hooks Signed-off-by: Jordan Hollinger --- lib/blueprinter/v2.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/blueprinter/v2.rb b/lib/blueprinter/v2.rb index 324f1542..70c7b061 100644 --- a/lib/blueprinter/v2.rb +++ b/lib/blueprinter/v2.rb @@ -2,13 +2,21 @@ module Blueprinter class V2 + Options = Struct.new( + :exclude_nil, + keyword_init: true, + ) + class << self - attr_accessor :views, :fields, :extensions, :blueprint_name + attr_accessor :views, :fields, :extensions, :options, :blueprint_name end self.views = {} self.fields = {} self.extensions = [] + self.options = Options.new( + exclude_nil: false, + ) self.blueprint_name = [] # Initialize subclass @@ -16,6 +24,7 @@ def self.inherited(subclass) subclass.views = { default: subclass } subclass.fields = fields.dup subclass.extensions = extensions.dup + subclass.options = options.dup subclass.blueprint_name = subclass.name ? [subclass.name] : blueprint_name.dup end