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

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/core/entities/config.rb,
lib/convenient_service/core/entities/config/exceptions.rb,
lib/convenient_service/core/entities/config/entities/concerns.rb,
lib/convenient_service/core/entities/config/entities/method_middlewares.rb,
lib/convenient_service/core/entities/config/entities/concerns/entities/stack.rb,
lib/convenient_service/core/entities/config/entities/concerns/entities/middleware.rb,
lib/convenient_service/core/entities/config/entities/concerns/entities/default_concern.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/commands/track_method_missing_commit_trigger.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/concerns/entities/middleware/commands/cast_middleware.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, Exceptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass:) ⇒ void

Parameters:

  • klass (Class)


27
28
29
30
31
32
33
34
# File 'lib/convenient_service/core/entities/config.rb', line 27

def initialize(klass:)
  @klass = klass

  ##
  # IMPORTANT: Intentionally initializes mutex in constructor to ensure thread-safety.
  #
  @mutex = ::Mutex.new
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



15
16
17
# File 'lib/convenient_service/core/entities/config.rb', line 15

def klass
  @klass
end

#mutexObject (readonly)

Returns the value of attribute mutex.



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

def mutex
  @mutex
end

Instance Method Details

#commit!(trigger: Constants::Triggers::USER) ⇒ Boolean

Commits config when called for the first time. Does nothing for the subsequent calls.

Parameters:

Returns:

  • (Boolean)

    true if called for the first time, false otherwise (similarly as Kernel#require).

See Also:



159
160
161
162
# File 'lib/convenient_service/core/entities/config.rb', line 159

def commit!(trigger: Constants::Triggers::USER)
  (committed? ? false : concerns.include!)
    .tap { Commands::TrackMethodMissingCommitTrigger.call(config: self, trigger: trigger) }
end

#committed?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/convenient_service/core/entities/config.rb', line 140

def committed?
  @committed ||= concerns.included?
end

#concernsConvenientService::Core::Entities::Config::Entities::Concerns #concerns(&configuration_block) ⇒ ConvenientService::Core::Entities::Config::Entities::Concerns

Sets or gets concerns for a service class.

Examples:

Getter

concerns

Setter

concerns(&configuration_block)

Overloads:



55
56
57
58
59
60
61
62
63
64
# File 'lib/convenient_service/core/entities/config.rb', line 55

def concerns(&configuration_block)
  if configuration_block
    assert_not_committed!

    @concerns ||= Entities::Concerns.new(klass: klass)
    @concerns.configure(&configuration_block)
  end

  @concerns || Entities::Concerns.new(klass: klass)
end

#method_missing_commits_counterConvenientService::Support::ThreadSafeCounter



123
124
125
# File 'lib/convenient_service/core/entities/config.rb', line 123

def method_missing_commits_counter
  @method_missing_commits_counter ||= Support::ThreadSafeCounter.new(max_value: Constants::Commits::METHOD_MISSING_MAX_TRIES)
end

#middlewares(method) ⇒ Hash{Symbol => Hash{Symbol => ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares}} #middlewares(method, scope: ) ⇒ Hash{Symbol => Hash{Symbol => ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares}} #middlewares(method, &configuration_block) ⇒ ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares #middlewares(method, scope: , &configuration_block) ⇒ ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares

Sets or gets middlewares for a service class.

Examples:

Getters

middlewares(:result)
middlewares(:result, scope: :instance)
middlewares(:result, scope: :class)

Setters

middlewares(:result, &configuration_block)
middlewares(:result, scope: :instance, &configuration_block)
middlewares(:result, scope: :class, &configuration_block)

Overloads:



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

def middlewares(method, scope: :instance, &configuration_block)
  @middlewares ||= {}
  @middlewares[scope] ||= {}

  if configuration_block
    assert_not_committed!

    @middlewares[scope][method] ||= Entities::MethodMiddlewares.new(scope: scope, method: method, klass: klass)
    @middlewares[scope][method].configure(&configuration_block)
    @middlewares[scope][method].define!
  end

  @middlewares[scope][method] || Entities::MethodMiddlewares.new(scope: scope, method: method, klass: klass)
end