Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/didit/object_functions.rb
Overview
Anything can be a service, so we add these static methods to the Object.
Class Method Summary collapse
-
.as_service ⇒ Object
Called when a class declares itself as being a service.
-
.inject(identifier) ⇒ Object
Called when a service wants to have something injected.
-
.inject_list(base_class, args) ⇒ Object
Requests a list of a specific base type to be injected.
-
.post_construct(method_symbol) ⇒ Object
Called after all services have been loaded.
Class Method Details
.as_service ⇒ Object
Called when a class declares itself as being a service
10 11 12 13 14 15 16 17 18 |
# File 'lib/didit/object_functions.rb', line 10 def self.as_service identifier = Didit::get_class_identifier(self) *folders, base_identifier = identifier.to_s.split("/") Didit::SERVICES[base_identifier.to_sym] = { identifier: identifier, class_object: self, class_instance: self.new } end |
.inject(identifier) ⇒ Object
Called when a service wants to have something injected
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/didit/object_functions.rb', line 35 def self.inject(identifier) service = Didit::service_object(self) raise "this object doesn't declare as_service" unless service service[:requires] = [] unless service[:requires] service[:requires] << { type: 'one', id: identifier } end |
.inject_list(base_class, args) ⇒ Object
Requests a list of a specific base type to be injected
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/didit/object_functions.rb', line 49 def self.inject_list(base_class, args) service = Didit::service_object(self) raise "this object doesn't declare as_service" unless service service[:requires] = [] unless service[:requires] service[:requires] << { type: 'multiple', id: base_class, var_name: args[:as] } end |
.post_construct(method_symbol) ⇒ Object
Called after all services have been loaded
23 24 25 26 27 28 29 |
# File 'lib/didit/object_functions.rb', line 23 def self.post_construct(method_symbol) service = Didit::service_object(self) raise "this object doesn't declare as_service" unless service service[:post_config] = [] unless service[:post_config] service[:post_config] << method_symbol end |