Class: Sys::Proc::Helper::Inflector

Inherits:
Object
  • Object
show all
Defined in:
lib/sys/proc/helper/inflector.rb

Overview

Inflector built on top of Dry::Inflector

Instance Method Summary collapse

Constructor Details

#initializeInflector

Returns a new instance of Inflector.



13
14
15
16
17
# File 'lib/sys/proc/helper/inflector.rb', line 13

def initialize
  require 'dry/inflector'

  @inflector = Dry::Inflector.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/sys/proc/helper/inflector.rb', line 29

def method_missing(method, *args, &block)
  if respond_to_missing?(method)
    @inflector.public_send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#resolve(loadable) ⇒ Object

Load constant from a loadable/requirable path

Parameters:

  • loadable (String)

Returns:

  • (Object)


23
24
25
26
27
# File 'lib/sys/proc/helper/inflector.rb', line 23

def resolve(loadable)
  require loadable

  @inflector.constantize(@inflector.classify(loadable))
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/sys/proc/helper/inflector.rb', line 37

def respond_to_missing?(method, include_private = false)
  return true if @inflector.respond_to?(method, include_private)

  super(method, include_private)
end