-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jordan Hollinger <[email protected]>
- Loading branch information
1 parent
25f7964
commit 9bcc80a
Showing
48 changed files
with
2,938 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blueprinter | ||
# An interface for running extension hooks | ||
class Hooks | ||
def initialize(extensions) | ||
@hooks = Extension.public_instance_methods(false).each_with_object({}) do |hook, acc| | ||
acc[hook] = extensions. | ||
select { |ext| ext.class.public_instance_methods(false).include? hook }. | ||
map { |ext| ext.public_method(hook) } | ||
end | ||
end | ||
|
||
# | ||
# Return true if any of "hook" returns truthy. | ||
# | ||
# @param hook [Symbol] Name of hook to call | ||
# @return [Boolean] | ||
# | ||
def any?(hook, *args) | ||
@hooks.fetch(hook).any? { |h| h.call(*args) } | ||
end | ||
|
||
# | ||
# Call the hooks in series, passing the output of one to the block, which returns the args for the next. | ||
# | ||
# If the hook requires multiple arguments, the block should return an array. | ||
# | ||
# @param hook [Symbol] Name of hook to call | ||
# @param initial_value [Object] The starting value for the block | ||
# @return [Object] The last hook's return value | ||
# | ||
def reduce(hook, initial_value) | ||
@hooks.fetch(hook).reduce(initial_value) do |val, h| | ||
args = yield val | ||
args.is_a?(Array) ? h.call(*args) : h.call(args) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'blueprinter/v2/base' | ||
require 'blueprinter/v2/fields' | ||
|
||
module Blueprinter | ||
module V2 | ||
autoload :Base, 'blueprinter/v2/base' | ||
autoload :DSL, 'blueprinter/v2/dsl' | ||
autoload :Extensions, 'blueprinter/v2/extensions' | ||
autoload :Extractor, 'blueprinter/v2/extractor' | ||
autoload :Formatter, 'blueprinter/v2/formatter' | ||
autoload :InstanceCache, 'blueprinter/v2/instance_cache' | ||
autoload :Reflection, 'blueprinter/v2/reflection' | ||
autoload :Render, 'blueprinter/v2/render' | ||
autoload :Serializer, 'blueprinter/v2/serializer' | ||
autoload :ViewBuilder, 'blueprinter/v2/view_builder' | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.