Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jhollinger committed Jul 23, 2024
1 parent 0787fc5 commit d2ab44c
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 37 deletions.
42 changes: 15 additions & 27 deletions lib/blueprinter.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions lib/blueprinter/association.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'blueprinter/field'

module Blueprinter
# @api private
class Association < Field
Expand Down
19 changes: 19 additions & 0 deletions lib/blueprinter/base.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 2 additions & 10 deletions lib/blueprinter/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require 'json'
require 'blueprinter/extensions'
require 'blueprinter/extractors/auto_extractor'

module Blueprinter
class Configuration
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions lib/blueprinter/empty_types.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'blueprinter/helpers/type_helpers'

module Blueprinter
EMPTY_COLLECTION = 'empty_collection'
EMPTY_HASH = 'empty_hash'
Expand Down
2 changes: 2 additions & 0 deletions spec/units/association_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'blueprinter/association'

describe Blueprinter::Association do
describe '#initialize' do
let(:blueprint) { Class.new(Blueprinter::Base) }
Expand Down
2 changes: 2 additions & 0 deletions spec/units/blueprint_validator_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/units/extensions_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'ostruct'
require 'blueprinter/extensions'

describe Blueprinter::Extensions do
let(:all_extensions) {
Expand Down
2 changes: 2 additions & 0 deletions spec/units/reflection_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'blueprinter/reflection'

describe Blueprinter::Reflection do
let(:category_blueprint) {
Class.new(Blueprinter::Base) do
Expand Down

0 comments on commit d2ab44c

Please sign in to comment.