diff --git a/lib/blueprinter.rb b/lib/blueprinter.rb index bf0c399c..f90a939d 100644 --- a/lib/blueprinter.rb +++ b/lib/blueprinter.rb @@ -1,7 +1,37 @@ # frozen_string_literal: true -require_relative 'blueprinter/base' -require_relative 'blueprinter/extension' - module Blueprinter + # Core + autoload :Association, 'blueprinter/association' + autoload :Base, 'blueprinter/base' + autoload :Configuration, 'blueprinter/configuration' + autoload :Deprecation, 'blueprinter/deprecation' + 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' + + # Errors & Validation + autoload :BlueprinterError, 'blueprinter/blueprinter_error' + autoload :BlueprintValidator, 'blueprinter/blueprint_validator' + autoload :Errors, 'blueprinter/errors' + + extend Configuration::Configurable end diff --git a/lib/blueprinter/association.rb b/lib/blueprinter/association.rb index 555c1afd..b94b97c6 100644 --- a/lib/blueprinter/association.rb +++ b/lib/blueprinter/association.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require_relative 'field' -require_relative 'blueprint_validator' - module Blueprinter # @api private class Association < Field diff --git a/lib/blueprinter/base.rb b/lib/blueprinter/base.rb index 0083dde3..04022df8 100644 --- a/lib/blueprinter/base.rb +++ b/lib/blueprinter/base.rb @@ -1,26 +1,5 @@ # frozen_string_literal: true -require_relative 'association' -require_relative 'blueprint_validator' -require_relative 'blueprinter_error' -require_relative 'configuration' -require_relative 'deprecation' -require_relative 'empty_types' -require_relative 'extractor' -require_relative 'extractors/association_extractor' -require_relative 'extractors/auto_extractor' -require_relative 'extractors/block_extractor' -require_relative 'extractors/hash_extractor' -require_relative 'extractors/public_send_extractor' -require_relative 'field' -require_relative 'formatters/date_time_formatter' -require_relative 'helpers/base_helpers' -require_relative 'helpers/type_helpers' -require_relative 'reflection' -require_relative 'transformer' -require_relative 'view_collection' -require_relative 'view' - module Blueprinter class Base include BaseHelpers diff --git a/lib/blueprinter/blueprint_validator.rb b/lib/blueprinter/blueprint_validator.rb index dc7a922d..865e9548 100644 --- a/lib/blueprinter/blueprint_validator.rb +++ b/lib/blueprinter/blueprint_validator.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative 'errors/invalid_blueprint' - module Blueprinter # @api private class BlueprintValidator diff --git a/lib/blueprinter/configuration.rb b/lib/blueprinter/configuration.rb index 04ef91fa..1a281ae2 100644 --- a/lib/blueprinter/configuration.rb +++ b/lib/blueprinter/configuration.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative 'extensions' - module Blueprinter class Configuration attr_accessor :association_default, :datetime_format, :deprecations, :field_default, :generator, :if, :method, @@ -47,13 +45,15 @@ def jsonify(blob) def valid_callable?(callable_name) VALID_CALLABLES.include?(callable_name) end - end - def self.configuration - @configuration ||= Configuration.new - end + module Configurable + def configuration + @configuration ||= Configuration.new + end - def self.configure - yield configuration if block_given? + 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 03debe98..5d36de74 100644 --- a/lib/blueprinter/empty_types.rb +++ b/lib/blueprinter/empty_types.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative 'helpers/type_helpers' - module Blueprinter EMPTY_COLLECTION = 'empty_collection' EMPTY_HASH = 'empty_hash' diff --git a/lib/blueprinter/errors.rb b/lib/blueprinter/errors.rb new file mode 100644 index 00000000..a3adb656 --- /dev/null +++ b/lib/blueprinter/errors.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Blueprinter + module Errors + autoload :InvalidBlueprint, 'blueprinter/errors/invalid_blueprint' + end +end diff --git a/lib/blueprinter/errors/invalid_blueprint.rb b/lib/blueprinter/errors/invalid_blueprint.rb index 97965653..dbd9c373 100644 --- a/lib/blueprinter/errors/invalid_blueprint.rb +++ b/lib/blueprinter/errors/invalid_blueprint.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'blueprinter/blueprinter_error' - module Blueprinter module Errors class InvalidBlueprint < Blueprinter::BlueprinterError; end