Module: Octiron::Support::Identifiers

Includes:
CamelCase, Constantize
Included in:
Events::Bus, Transmogrifiers::Registry
Defined in:
lib/octiron/support/identifiers.rb

Overview

See Also:

  • Identifiers::identify

Instance Method Summary collapse

Methods included from Constantize

#constantize

Methods included from CamelCase

#camel_case

Instance Method Details

#identify(name) ⇒ Object

This function “identifies” an object, i.e. returns a unique ID according to the octiron logic. That means that:

  • For classes, a stringified version is returned

  • For hashes, the hash itself is returned

  • Strings are interpreted as constant names, and are returned fully qualified.

  • Everything else is considered to be a constant name in the default namespace. This requires access to a @default_namespace variable in the including class.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/octiron/support/identifiers.rb', line 30

def identify(name)
  case name
  when Class
    return name.to_s
  when Hash
    return name
  when String
    return constantize(name).to_s
  when nil
    raise NameError, "Can't identify 'nil'!"
  else
    return constantize("#{@default_namespace}::#{camel_case(name)}").to_s
  end
end