Module: Didit

Defined in:
lib/didit.rb,
lib/didit/version.rb

Overview


Contains service retrieval functions that can be called from
anywhere outside the services contexts to get an 'in'. Great for
calling from a Rails controller for example

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.get_class_identifier(clazz) ⇒ Object

Returns a symbol of the class that it is passed



33
34
35
# File 'lib/didit.rb', line 33

def self.get_class_identifier(clazz)
	Didit::underscore(clazz.name).to_sym
end

.service(identifier) ⇒ Object

Get the instance of a service with the name ‘identifier`



57
58
59
# File 'lib/didit.rb', line 57

def self.service(identifier)
	return Didit::SERVICES[identifier][:class_instance]
end

.service_object(clazz) ⇒ Object

Return the service object for a specific class



40
41
42
43
# File 'lib/didit.rb', line 40

def self.service_object(clazz)
	identifier = Didit::get_class_identifier(clazz)
	return Didit::SERVICES.find { |(key, val)| val[:identifier] == identifier }.last
end

.services_with_base(clazz) ⇒ Object

Returns a list of services that all have a particular object base



48
49
50
51
52
# File 'lib/didit.rb', line 48

def self.services_with_base(clazz)
	Didit::SERVICES\
		.find_all { |key, service| service[:class_instance].is_a? clazz }\
		.map { |(key, service)| service[:class_instance] }
end