Module: ConvenientService::Core::Concern::ClassMethods
- Defined in:
- lib/convenient_service/core/concern/class_methods.rb
Instance Method Summary collapse
-
#commit_config!(trigger: ConvenientService::Core::Constants::Triggers::USER) ⇒ Boolean
Commits config when called for the first time.
- #concerns ⇒ Object
-
#has_committed_config? ⇒ Boolean
Returns
truewhen config is committed, otherwise -false. - #middlewares ⇒ Object
-
#new(*args, **kwargs, &block) ⇒ Object
Can be any type.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ void (private)
Note:
Config commitment via a missing class method is very common. Convenient Service Standard config does that by .new, .result and .step most of the time.
This method returns an undefined value.
Commits config. In other words, includes concerns into the mixing class.
If method is still NOT defined, raises NoMethodError, otherwise - retries to call the method.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 120 def method_missing(method, *args, **kwargs, &block) commit_config!(trigger: Constants::Triggers::CLASS_METHOD_MISSING) return ::ConvenientService.reraise { super } unless Utils::Module.class_method_defined?(self, method, public: true, protected: false, private: false) return ::ConvenientService.reraise { super } if middlewares(method, scope: :class).defined_without_super_method? ConvenientService.logger.debug { "[Core] Committed config for `#{self}` | Triggered by `method_missing` | Method: `.#{method}`" } __send__(method, *args, **kwargs, &block) end |
Instance Method Details
#commit_config!(trigger: ConvenientService::Core::Constants::Triggers::USER) ⇒ Boolean
Commits config when called for the first time. Does nothing for the subsequent calls.
49 50 51 52 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 49 def commit_config!(trigger: ConvenientService::Core::Constants::Triggers::USER) (@__convenient_service_config__ ||= Entities::Config.new(klass: self)).commit!(trigger: trigger) .tap { ConvenientService.logger.debug { "[Core] Committed config for `#{self}` | Triggered by `.commit_config!(trigger: #{trigger.inspect})` " } } end |
#concerns ⇒ Object
14 15 16 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 14 def concerns(...) (@__convenient_service_config__ ||= Entities::Config.new(klass: self)).concerns(...) end |
#has_committed_config? ⇒ Boolean
Returns true when config is committed, otherwise - false.
32 33 34 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 32 def has_committed_config? (@__convenient_service_config__ ||= Entities::Config.new(klass: self)).committed? end |
#middlewares ⇒ Object
25 26 27 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 25 def middlewares(...) (@__convenient_service_config__ ||= Entities::Config.new(klass: self)).middlewares(...) end |
#new(*args, **kwargs, &block) ⇒ Object
Returns Can be any type.
65 66 67 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 65 def new(*args, **kwargs, &block) has_committed_config? ? super : method_missing(:new, *args, **kwargs, &block) end |