class Lamassu::NamespaceResolver

Default namespace resolver used for scopes in Lamassu

If target is a symbol or string, it is used as is. If passed a Module, it is translated underscorized string. For any other object, it resolves the targets class and it's translated as above.

Public Class Methods

new(inflector: Dry::Inflector.new) click to toggle source
# File lib/lamassu/namespace_resolver.rb, line 12
def initialize(inflector: Dry::Inflector.new)
  @inflector = inflector
end

Public Instance Methods

call(target) click to toggle source
# File lib/lamassu/namespace_resolver.rb, line 16
def call(target)
  case target
  when Module
    coerce_module(target)
  when String, Symbol
    coerce_string(target)
  else
    coerce_object(target)
  end
end

Private Instance Methods

coerce_module(target) click to toggle source
# File lib/lamassu/namespace_resolver.rb, line 37
def coerce_module(target)
  @inflector.underscore(target)
end
coerce_object(target) click to toggle source
# File lib/lamassu/namespace_resolver.rb, line 33
def coerce_object(target)
  @inflector.underscore(target.class)
end
coerce_string(target) click to toggle source
# File lib/lamassu/namespace_resolver.rb, line 29
def coerce_string(target)
  target.to_s
end