Module: SkinnyControllers::Lookup::Model

Defined in:
lib/skinny_controllers/lookup/model.rb

Class Method Summary collapse

Class Method Details

.class_from_operation(operation_name) ⇒ Class

Returns class based on the operation.

Examples:

‘ObjectOperations::Verb’ => Object


Returns:

  • (Class)

    class based on the operation



10
11
12
13
14
15
16
17
# File 'lib/skinny_controllers/lookup/model.rb', line 10

def class_from_operation(operation_name)
  # "Namespace::Model" => "Model"
  model_name = Model.name_from_operation(operation_name)
  # model_name.demodulize

  # "Model" => Model
  model_name.constantize
end

.name_from_operation(operation_name) ⇒ String

Returns the model name corresponding to the operation.

Examples:

‘Namespace::ModelOperation::Verb’ => ‘Model’


Returns:

  • (String)

    the model name corresponding to the operation



21
22
23
24
25
26
27
28
29
30
# File 'lib/skinny_controllers/lookup/model.rb', line 21

def name_from_operation(operation_name)
  # operation_name is something of the form:
  # Namespace::ModelOperations::Verb

  # Namespace::ModelOperations::Verb => Namespace::ModelOperations
  namespace = operation_name.deconstantize

  # ModelOperations => Model
  namespace.gsub(SkinnyControllers.operations_suffix, '')
end