Class: DuckMap::ClassHelpers

Inherits:
Object
  • Object
show all
Defined in:
lib/duck_map/class_helpers.rb

Overview

Simple helper class that tries to find controller and model classes based on a controller name.

Class Method Summary collapse

Class Method Details

.get_controller_class(controller_name) ⇒ Object

Attempts to automagically determine the controller class name based on the named route. returns [Class]



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/duck_map/class_helpers.rb', line 10

def self.get_controller_class(controller_name)
  controller = nil

  begin

    controller = "#{controller_name.camelize.pluralize}Controller".constantize

  rescue Exception => e
    # once upon a time, I was logging these exceptions, however, it made the log files very noisy.
    # I expect to have the exceptions occur.  i plan on doing a little more on this area later.
    controller = nil

    begin

      controller = "#{controller_name.camelize.singularize}Controller".constantize

    rescue Exception => e
      # once upon a time, I was logging these exceptions, however, it made the log files very noisy.
      # I expect to have the exceptions occur.  i plan on doing a little more on this area later.
    end
  end

  return controller
end

.get_model_class(controller_name) ⇒ Object

Attempts to automagically determine the model class name based on the named route. returns [Class]



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/duck_map/class_helpers.rb', line 38

def self.get_model_class(controller_name)
  value = nil

  begin

    value = controller_name.camelize.singularize.constantize

  rescue Exception => e
    # once upon a time, I was logging these exceptions, however, it made the log files very noisy.
    # I expect to have the exceptions occur.  i plan on doing a little more on this area later.
  end

  return value
end