Module: SkinnyControllers::Lookup::Model
- Defined in:
- lib/skinny_controllers/lookup/model.rb
Class Method Summary collapse
-
.class_from_operation(operation_name) ⇒ Class
Class based on the operation.
-
.name_from_operation(operation_name) ⇒ String
The model name corresponding to the operation.
Class Method Details
.class_from_operation(operation_name) ⇒ Class
Returns class based on the operation.
9 10 11 12 13 14 15 16 |
# File 'lib/skinny_controllers/lookup/model.rb', line 9 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.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/skinny_controllers/lookup/model.rb', line 20 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 # Namespace::ModelOperations => ModelOperations # nested_namespace = namespace.demodulize nested_namespace = namespace.gsub(SkinnyControllers.operations_namespace, '') # ModelOperations => Model nested_namespace.gsub(SkinnyControllers.operations_suffix, '') end |