Class: ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares

Inherits:
Object
  • Object
show all
Includes:
Support::Delegate
Defined in:
lib/convenient_service/core/entities/config/entities/method_middlewares.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/stack.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/concern.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/constants.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/base.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/commands/generate_stack_name.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/classic.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creators/base.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creators/with.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/base/concern.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/concern.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/base/constants.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/cast_caller.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/concern/class_methods.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creators/observable.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/concern/instance_methods.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern/class_methods.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/cast_container.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern/instance_methods.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_callers.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/base/concern/class_methods.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/concern/class_methods.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/entities/method_chain.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/base/structs/intended_method.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/commands/normalize_env.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/base/concern/instance_methods.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/concern/instance_methods.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creators/observable/entities/event.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/resolve_methods_middlewares_callers.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/base/commands/create_observable_middleware.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/commands/create_observable_middleware.rb

Defined Under Namespace

Modules: Commands, Entities

Instance Method Summary collapse

Methods included from Support::Delegate::ClassMethodsForForwardable

#delegate

Constructor Details

#initialize(scope:, method:, klass:) ⇒ void

Parameters:

  • scope (:instance, :class)
  • method (Symbol, String)
  • klass (Class)


20
21
22
23
24
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 20

def initialize(scope:, method:, klass:)
  @scope = scope
  @method = method
  @klass = klass
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

Returns:

  • (Boolean, nil)


105
106
107
108
109
110
111
112
113
114
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 105

def ==(other)
  return unless other.instance_of?(self.class)

  return false if scope != other.scope
  return false if method != other.method
  return false if klass != other.klass
  return false if stack != other.stack

  true
end

#call(env, original_method) ⇒ Object

Parameters:

  • env (Hash)
  • original_method (Proc)

Returns:

  • (Object)


84
85
86
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 84

def call(env, original_method)
  stack.dup.use(original_method).call(env.merge(method: method))
end

#configure(&configuration_block) ⇒ ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares

Parameters:

  • configuration_block (Proc)

Returns:



59
60
61
62
63
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 59

def configure(&configuration_block)
  Utils::Proc.exec_config(configuration_block, stack)

  self
end

#define!Boolean

Note:

Works in a similar way as Kernel.require.

Returns:

  • (Boolean)


70
71
72
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 70

def define!
  caller.define_method_callers!(scope, method, container)
end

#defined?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 37

def defined?
  Utils::Module.has_own_instance_method?(methods_middlewares_callers, method)
end

#defined_without_super_method?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 51

def defined_without_super_method?
  self.defined? && !super_method_defined?
end

#no_super_method_exception_message_for(entity) ⇒ String

Parameters:

  • entity (Object, Class)

Returns:

  • (String)


30
31
32
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 30

def no_super_method_exception_message_for(entity)
  "super: no superclass method `#{method}' for #{entity}"
end

#resolve_super_method(entity) ⇒ Method?

Parameters:

  • entity (Object, Class)

Returns:

  • (Method, nil)


95
96
97
98
99
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 95

def resolve_super_method(entity)
  klass.commit_config!(trigger: Constants::Triggers::RESOLVE_METHOD_MIDDLEWARES_SUPER_METHOD)

  container.resolve_super_method(method, entity)
end

#super_method_defined?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 44

def super_method_defined?
  container.super_method_defined?(method)
end

#to_aArray<ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware>

Returns:

  • (Array<ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware>)


119
120
121
# File 'lib/convenient_service/core/entities/config/entities/method_middlewares.rb', line 119

def to_a
  stack.to_a
end