From fa53b927cbad931abe9ac31104af64fc098cb2bd 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 | 6 +++++- lib/blueprinter/v2/options.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 lib/blueprinter/v2/options.rb diff --git a/lib/blueprinter/v2.rb b/lib/blueprinter/v2.rb index 324f1542..76c169f4 100644 --- a/lib/blueprinter/v2.rb +++ b/lib/blueprinter/v2.rb @@ -2,13 +2,16 @@ module Blueprinter class V2 + autoload :Options, 'blueprinter/v2/options' + 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::Options.new(Options::DEFAULTS) self.blueprint_name = [] # Initialize subclass @@ -16,6 +19,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 diff --git a/lib/blueprinter/v2/options.rb b/lib/blueprinter/v2/options.rb new file mode 100644 index 00000000..3b4c9ca2 --- /dev/null +++ b/lib/blueprinter/v2/options.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Blueprinter + class V2 + module Options + Options = Struct.new( + :exclude_nil, + keyword_init: true + ) + + DEFAULTS = { + exclude_nil: false + }.freeze + end + end +end