Module: ConvenientService::Core::Concern::ClassMethods
- Defined in:
- lib/convenient_service/core/concern/class_methods.rb
Instance Method Summary collapse
- #__convenient_service_config__ ⇒ Object
-
#commit_config!(trigger: ConvenientService::Core::Constants::Triggers::USER) ⇒ Boolean
Commits config when called for the first time.
- #concerns ⇒ Object
- #entity ⇒ Object
-
#has_committed_config? ⇒ Boolean
Returns ‘true` when config is committed, otherwise - `false`.
- #middlewares ⇒ Object
-
#new(*args, **kwargs, &block) ⇒ Object
Can be any type.
- #options ⇒ Object
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`.
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 148 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
#__convenient_service_config__ ⇒ Object
21 22 23 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 21 def __convenient_service_config__ @__convenient_service_config__ ||= Entities::Config.new(klass: self) end |
#commit_config!(trigger: ConvenientService::Core::Constants::Triggers::USER) ⇒ Boolean
Commits config when called for the first time. Does nothing for the subsequent calls.
74 75 76 77 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 74 def commit_config!(trigger: ConvenientService::Core::Constants::Triggers::USER) __convenient_service_config__.commit!(trigger: trigger) .tap { ConvenientService.logger.debug { "[Core] Committed config for `#{self}` | Triggered by `.commit_config!(trigger: #{trigger.inspect})` " } } end |
#concerns ⇒ Object
33 34 35 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 33 def concerns(...) __convenient_service_config__.concerns(...) end |
#entity ⇒ Object
54 55 56 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 54 def entity(...) __convenient_service_config__.entity(...) end |
#has_committed_config? ⇒ Boolean
Returns ‘true` when config is committed, otherwise - `false`.
61 62 63 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 61 def has_committed_config? __convenient_service_config__.committed? end |
#middlewares ⇒ Object
40 41 42 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 40 def middlewares(...) __convenient_service_config__.middlewares(...) end |
#new(*args, **kwargs, &block) ⇒ Object
Returns Can be any type.
90 91 92 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 90 def new(*args, **kwargs, &block) has_committed_config? ? super : method_missing(:new, *args, **kwargs, &block) end |
#options ⇒ Object
47 48 49 |
# File 'lib/convenient_service/core/concern/class_methods.rb', line 47 def (...) __convenient_service_config__.(...) end |