Class: ConvenientService::Core::Entities::Config
- Inherits:
-
Object
- Object
- ConvenientService::Core::Entities::Config
- 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
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
-
#commit!(trigger: Constants::Triggers::USER) ⇒ Boolean
Commits config when called for the first time.
- #committed? ⇒ Boolean
-
#concerns(&configuration_block) ⇒ Object
Sets or gets concerns for a service class.
- #initialize(klass:) ⇒ void constructor
- #method_missing_commits_counter ⇒ ConvenientService::Support::ThreadSafeCounter
-
#middlewares(method, scope: :instance, &configuration_block) ⇒ Object
Sets or gets middlewares for a service class.
Constructor Details
#initialize(klass:) ⇒ void
21 22 23 |
# File 'lib/convenient_service/core/entities/config.rb', line 21 def initialize(klass:) @klass = klass end |
Instance Attribute Details
#klass ⇒ Object (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.
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
129 130 131 |
# File 'lib/convenient_service/core/entities/config.rb', line 129 def committed? @committed ||= concerns.included? end |
#concerns ⇒ ConvenientService::Core::Entities::Config::Entities::Concerns #concerns(&configuration_block) ⇒ ConvenientService::Core::Entities::Config::Entities::Concerns
Sets or gets concerns for a service class.
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_counter ⇒ ConvenientService::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.
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 |