Module: AutoCamelize

Defined in:
lib/docusign/extensions.rb

Overview

AutoCamelize

This module enables a class to automatically map Ruby-esque snake_case method calls to the equivalent camelCase calls. If a method with a camelCase equivalent is found, we alias the snake_case method on the class, to avoid tripping method_missing for the same method in the future.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/docusign/extensions.rb', line 11

def method_missing(method_name, *args, &block)
  ds_name = ds_equivalent(method_name)

  if ds_name && respond_to?(ds_name)
    self.class.class_eval %Q{
      alias :#{method_name} :#{ds_name}
    }

    send method_name, *args, &block
  else
    super
  end
end

Instance Method Details

#ds_equivalent(string) ⇒ Object

Find the equivalent built-in method name, if there is one. Example: ds_equivalent(‘pdf_bytes’) => ‘pDFBytes’



29
30
31
32
# File 'lib/docusign/extensions.rb', line 29

def ds_equivalent(string)
  string = string.to_s.camelize(:lower)
  methods.find { |m| m.downcase == string.downcase }
end