Skip to content

Commit

Permalink
Add options for things that don't make sense as extension hooks
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Hollinger <[email protected]>
  • Loading branch information
jhollinger committed Jul 25, 2024
1 parent e0801c7 commit fa53b92
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/blueprinter/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@

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
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

Expand Down
16 changes: 16 additions & 0 deletions lib/blueprinter/v2/options.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fa53b92

Please sign in to comment.