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/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/caller/commands/define_method_middlewares_caller.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)


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

def initialize(klass:)
  @klass = klass
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

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:



148
149
150
151
# File 'lib/convenient_service/core/entities/config.rb', line 148

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

#committed?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/convenient_service/core/entities/config.rb', line 129

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:



44
45
46
47
48
49
50
51
52
53
# File 'lib/convenient_service/core/entities/config.rb', line 44

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



112
113
114
# File 'lib/convenient_service/core/entities/config.rb', line 112

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:



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/convenient_service/core/entities/config.rb', line 94

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