Class: Kamaze::Project::Helper::Inflector

Inherits:
Object
  • Object
show all
Defined in:
lib/kamaze/project/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/kamaze/project/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



31
32
33
34
35
36
37
# File 'lib/kamaze/project/helper/inflector.rb', line 31

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:



23
24
25
26
27
28
29
# File 'lib/kamaze/project/helper/inflector.rb', line 23

def resolve(loadable)
  loadable = loadable.to_s.empty? ? nil : loadable.to_s

  require loadable

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

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

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/kamaze/project/helper/inflector.rb', line 39

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

  super(method, include_private)
end