Class: ActionCommand::Utils
- Inherits:
-
Object
- Object
- ActionCommand::Utils
- Defined in:
- lib/action_command/utils.rb
Overview
class with utilities for working with action_commands
Class Method Summary collapse
-
.find_object(cls, item) ⇒ Object
Used for cases where you might want to pass an action a User object, or the integer ID of a user object, or the unique email of a user object, and have the command operate on the user object.
Class Method Details
.find_object(cls, item) ⇒ Object
Used for cases where you might want to pass an action a User object, or the integer ID of a user object, or the unique email of a user object, and have the command operate on the user object. Converts an item into an object as follows:
-
If item is an object of cls, then returns it
-
If item is an integer, then assumes its and id and returns cls.find(item)
-
Otherwise, executes the code block and passes it item.
13 14 15 16 17 |
# File 'lib/action_command/utils.rb', line 13 def self.find_object(cls, item) return item if item.is_a? cls return cls.find(item) if item.is_a? Integer return yield(item) end |