From d2ab44ca3ca83f5d996ffc2d8789393e974e6ddb Mon Sep 17 00:00:00 2001 From: Jordan Hollinger Date: Tue, 23 Jul 2024 14:36:29 -0400 Subject: [PATCH] wip --- lib/blueprinter.rb | 42 +++++++++----------------- lib/blueprinter/association.rb | 2 ++ lib/blueprinter/base.rb | 19 ++++++++++++ lib/blueprinter/configuration.rb | 12 ++------ lib/blueprinter/empty_types.rb | 2 ++ spec/units/association_spec.rb | 2 ++ spec/units/blueprint_validator_spec.rb | 2 ++ spec/units/extensions_spec.rb | 1 + spec/units/reflection_spec.rb | 2 ++ 9 files changed, 47 insertions(+), 37 deletions(-) diff --git a/lib/blueprinter.rb b/lib/blueprinter.rb index f90a939d..2b001196 100644 --- a/lib/blueprinter.rb +++ b/lib/blueprinter.rb @@ -1,37 +1,25 @@ # frozen_string_literal: true module Blueprinter - # Core - autoload :Association, 'blueprinter/association' autoload :Base, 'blueprinter/base' + autoload :BlueprinterError, 'blueprinter/blueprinter_error' autoload :Configuration, 'blueprinter/configuration' - autoload :Deprecation, 'blueprinter/deprecation' + autoload :Errors, 'blueprinter/errors' autoload :Extension, 'blueprinter/extension' - autoload :Extensions, 'blueprinter/extensions' - autoload :Field, 'blueprinter/field' - autoload :Reflection, 'blueprinter/reflection' - autoload :View, 'blueprinter/view' - autoload :ViewCollection, 'blueprinter/view_collection' - - # Extractors & Transfomers - autoload :AssociationExtractor, 'blueprinter/extractors/association_extractor' - autoload :AutoExtractor, 'blueprinter/extractors/auto_extractor' - autoload :BlockExtractor, 'blueprinter/extractors/block_extractor' - autoload :Extractor, 'blueprinter/extractor' - autoload :HashExtractor, 'blueprinter/extractors/hash_extractor' - autoload :PublicSendExtractor, 'blueprinter/extractors/public_send_extractor' - autoload :Transformer, 'blueprinter/transformer' - # Helpers & Types - autoload :BaseHelpers, 'blueprinter/helpers/base_helpers' - autoload :DateTimeFormatter, 'blueprinter/formatters/date_time_formatter' - autoload :EmptyTypes, 'blueprinter/empty_types' - autoload :TypeHelpers, 'blueprinter/helpers/type_helpers' + class << self + # @return [Configuration] + def configuration + @_configuration ||= Configuration.new + end - # Errors & Validation - autoload :BlueprinterError, 'blueprinter/blueprinter_error' - autoload :BlueprintValidator, 'blueprinter/blueprint_validator' - autoload :Errors, 'blueprinter/errors' + def configure + yield(configuration) if block_given? + end - extend Configuration::Configurable + # Resets global configuration. + def reset_configuration! + @_configuration = nil + end + end end diff --git a/lib/blueprinter/association.rb b/lib/blueprinter/association.rb index b94b97c6..2fc69aee 100644 --- a/lib/blueprinter/association.rb +++ b/lib/blueprinter/association.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'blueprinter/field' + module Blueprinter # @api private class Association < Field diff --git a/lib/blueprinter/base.rb b/lib/blueprinter/base.rb index 04022df8..989fa9d5 100644 --- a/lib/blueprinter/base.rb +++ b/lib/blueprinter/base.rb @@ -1,5 +1,24 @@ # frozen_string_literal: true +require 'blueprinter/association' +require 'blueprinter/blueprint_validator' +require 'blueprinter/deprecation' +require 'blueprinter/empty_types' +require 'blueprinter/extractor' +require 'blueprinter/extractors/association_extractor' +require 'blueprinter/extractors/auto_extractor' +require 'blueprinter/extractors/block_extractor' +require 'blueprinter/extractors/hash_extractor' +require 'blueprinter/extractors/public_send_extractor' +require 'blueprinter/field' +require 'blueprinter/formatters/date_time_formatter' +require 'blueprinter/helpers/base_helpers' +require 'blueprinter/helpers/type_helpers' +require 'blueprinter/reflection' +require 'blueprinter/transformer' +require 'blueprinter/view_collection' +require 'blueprinter/view' + module Blueprinter class Base include BaseHelpers diff --git a/lib/blueprinter/configuration.rb b/lib/blueprinter/configuration.rb index b56c94d4..ce19178e 100644 --- a/lib/blueprinter/configuration.rb +++ b/lib/blueprinter/configuration.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true require 'json' +require 'blueprinter/extensions' +require 'blueprinter/extractors/auto_extractor' module Blueprinter class Configuration @@ -47,15 +49,5 @@ def jsonify(blob) def valid_callable?(callable_name) VALID_CALLABLES.include?(callable_name) end - - module Configurable - def configuration - @configuration ||= Configuration.new - end - - def configure - yield configuration if block_given? - end - end end end diff --git a/lib/blueprinter/empty_types.rb b/lib/blueprinter/empty_types.rb index 5d36de74..0a881a7c 100644 --- a/lib/blueprinter/empty_types.rb +++ b/lib/blueprinter/empty_types.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'blueprinter/helpers/type_helpers' + module Blueprinter EMPTY_COLLECTION = 'empty_collection' EMPTY_HASH = 'empty_hash' diff --git a/spec/units/association_spec.rb b/spec/units/association_spec.rb index 7478ed3a..01e8c148 100644 --- a/spec/units/association_spec.rb +++ b/spec/units/association_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'blueprinter/association' + describe Blueprinter::Association do describe '#initialize' do let(:blueprint) { Class.new(Blueprinter::Base) } diff --git a/spec/units/blueprint_validator_spec.rb b/spec/units/blueprint_validator_spec.rb index 159b623b..c058ebfa 100644 --- a/spec/units/blueprint_validator_spec.rb +++ b/spec/units/blueprint_validator_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'blueprinter/blueprint_validator' + describe Blueprinter::BlueprintValidator do describe 'validate!' do context 'when provided object subclasses Blueprinter::Base' do diff --git a/spec/units/extensions_spec.rb b/spec/units/extensions_spec.rb index eb985197..09a341b3 100644 --- a/spec/units/extensions_spec.rb +++ b/spec/units/extensions_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'ostruct' +require 'blueprinter/extensions' describe Blueprinter::Extensions do let(:all_extensions) { diff --git a/spec/units/reflection_spec.rb b/spec/units/reflection_spec.rb index 89955359..2f86490d 100644 --- a/spec/units/reflection_spec.rb +++ b/spec/units/reflection_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'blueprinter/reflection' + describe Blueprinter::Reflection do let(:category_blueprint) { Class.new(Blueprinter::Base) do