module SkinnyControllers::Lookup::Model

Public Instance Methods

class_from_operation(operation_name) click to toggle source

@example 'ObjectOperations::Verb' => Object

@return [Class] class based on the operation

# 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) click to toggle source

@example 'Namespace::ModelOperation::Verb' => 'Model' @return [String] the model name corresponding to the operation

# 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