Class: DRYParams::Naming

Inherits:
Object
  • Object
show all
Defined in:
lib/dryparams/naming.rb

Overview

The class returns the different names available for a given controller.

Instance Method Summary collapse

Constructor Details

#initialize(controller_instance) ⇒ self

Parameters:

  • controller_instance (ActionController::Base)

    The controller used to determine the different names.



9
10
11
# File 'lib/dryparams/naming.rb', line 9

def initialize(controller_instance)
  @controller = controller_instance
end

Instance Method Details

#klassString

Returns the model name associated to the controller.

Returns:

  • (String)

    the model name associated to the controller.



28
29
30
# File 'lib/dryparams/naming.rb', line 28

def klass
  @klass ||= @controller.controller_name.classify
end

#modelClass

Returns the model class associated to the controller.

Returns:

  • (Class)

    the model class associated to the controller.



14
15
16
17
18
19
20
# File 'lib/dryparams/naming.rb', line 14

def model
  @model ||= begin
    klass.constantize
  rescue NameError
    nil
  end
end

#objectString

Returns the object name from the controller.

Returns:

  • (String)

    the object name from the controller.



23
24
25
# File 'lib/dryparams/naming.rb', line 23

def object
  @object ||= klass.downcase
end