-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,146 additions
and
1,184 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 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
2 changes: 1 addition & 1 deletion
2
lib/convenient_service/core/entities/method_middlewares/entities.rb
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
143 changes: 143 additions & 0 deletions
143
lib/convenient_service/core/entities/method_middlewares/entities/caller.rb
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,143 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Core | ||
module Entities | ||
class MethodMiddlewares | ||
module Entities | ||
class Caller | ||
include Support::Delegate | ||
|
||
## | ||
# @!attribute [r] container | ||
# @return [ConvenientService::Core::Entities::MethodMiddlewares::Entities::Container] | ||
# | ||
attr_reader :container | ||
|
||
## | ||
# @return [Class] | ||
# | ||
delegate :klass, to: :container | ||
|
||
## | ||
# @return [Module, nil] | ||
# | ||
delegate :methods_middlewares_callers, to: :container | ||
|
||
## | ||
# @return [Array<Class, Module>] | ||
# | ||
delegate :ancestors, to: :klass | ||
|
||
## | ||
# @param container [ConvenientService::Core::Entities::MethodMiddlewares::Entities::Container] | ||
# @return [void] | ||
# | ||
def initialize(container:) | ||
@container = container | ||
end | ||
|
||
## | ||
# @param method_name [Symbol, String] | ||
# @return [UnboundMethod, nil] | ||
# | ||
def super_method_defined?(method_name) | ||
Utils::Bool.to_bool(resolve_unbound_super_method(method_name)) | ||
end | ||
|
||
## | ||
# Returns ancestors before the `methods_middlewares_callers` module. See the example below. | ||
# When ancestors do NOT contain `methods_middlewares_callers`, returns an empty array. | ||
# | ||
# @return [Array<Class, Module>] | ||
# | ||
# @example The entity is an object. | ||
# class Service | ||
# include ConvenientService::Core | ||
# | ||
# middlewares :result do | ||
# use ConvenientService::Plugins::Common::NormalizesEnv | ||
# end | ||
# end | ||
# | ||
# entity = Service.new | ||
# | ||
# entity.class.ancestors | ||
# # [Service::InstanceMethodsMiddlewaresCallers, Service, ConvenientService::Core::InstanceMethods, ConvenientService::Core, ConvenientService::Support::Concern, Object, Kernel, BasicObject] | ||
# | ||
# ancestors_greater_than_methods_middlewares_callers # For the entity defined above. | ||
# # [Service, ConvenientService::Core::InstanceMethods, ConvenientService::Core, ConvenientService::Support::Concern, Object, Kernel, BasicObject] | ||
# | ||
# @example The entity is class. | ||
# class Service | ||
# include ConvenientService::Core | ||
# | ||
# middlewares :result, scope: :class do | ||
# use ConvenientService::Plugins::Common::NormalizesEnv | ||
# end | ||
# end | ||
# | ||
# entity = Service | ||
# | ||
# entity.singleton_class.ancestors | ||
# # [Service::ClassMethodsMiddlewaresCallers, #<Class:Service>, ConvenientService::Core::ClassMethods, #<Class:Object>, #<Class:BasicObject>, Class, Module, Object, Kernel, BasicObject] | ||
# | ||
# ancestors_greater_than_methods_middlewares_callers # For the entity defined above. | ||
# # [#<Class:Service>, ConvenientService::Core::ClassMethods, #<Class:Object>, #<Class:BasicObject>, Class, Module, Object, Kernel, BasicObject]# [Service::ClassMethodsMiddlewaresCallers, #<Class:Service>, ConvenientService::Core::ClassMethods, #<Class:Object>, #<Class:BasicObject>, Class, Module, Object, Kernel, BasicObject] | ||
# | ||
# @internal | ||
# NOTE: greater than -> futher in the inheritance chain than | ||
# https://ruby-doc.org/core-2.7.0/Module.html#method-i-3E | ||
# | ||
# NOTE: lower than -> closer in the inheritance chain than | ||
# https://ruby-doc.org/core-2.7.0/Module.html#method-i-ancestors | ||
# | ||
def ancestors_greater_than_methods_middlewares_callers | ||
Utils::Array.keep_after(ancestors, methods_middlewares_callers) | ||
end | ||
|
||
## | ||
# @param method_name [Symbol, String] | ||
# @return [UnboundMethod, nil] | ||
# | ||
def resolve_unbound_super_method(method_name) | ||
Utils::Array.find_yield(ancestors_greater_than_methods_middlewares_callers) { |ancestor| Utils::Module.get_own_instance_method(ancestor, method_name, private: true) } | ||
end | ||
|
||
## | ||
# @param method_name [Symbol, String] | ||
# @param entity [Class, Object] | ||
# @return [Method, nil] | ||
# | ||
def resolve_super_method(method_name, entity) | ||
unbound_super_method = resolve_unbound_super_method(method_name) | ||
|
||
return unless unbound_super_method | ||
|
||
unbound_super_method.bind(entity) | ||
end | ||
|
||
## | ||
# @param other [ConvenientService::Core::Entities::MethodMiddlewares::Entities::Callers::Base, Object] | ||
# @return [Boolean] | ||
# | ||
def ==(other) | ||
return unless other.instance_of?(self.class) | ||
|
||
return false if container != other.container | ||
|
||
true | ||
end | ||
|
||
## | ||
# @return [Hash] | ||
# | ||
def to_kwargs | ||
{container: container} | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
5 changes: 0 additions & 5 deletions
5
lib/convenient_service/core/entities/method_middlewares/entities/callers.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.