module Didit


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

Constants

SERVICES
VERSION

Public Class Methods

get_class_identifier(clazz) click to toggle source

Returns a symbol of the class that it is passed

# File lib/didit.rb, line 33
def self.get_class_identifier(clazz)
        Didit::underscore(clazz.name).to_sym
end
service(identifier) click to toggle source

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

# File lib/didit.rb, line 57
def self.service(identifier)
        return Didit::SERVICES[identifier][:class_instance]
end
service_object(clazz) click to toggle source

Return the service object for a specific class

# 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) click to toggle source

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

# 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

Private Class Methods

underscore(word) click to toggle source

Convert a word cased word into a underscored version of it

# File lib/didit.rb, line 19
def self.underscore(word)
        word.gsub!(/::/, '/')
        word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
        word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
        word.tr!("-", "_")
        word.downcase!
        word
end