Class: ActionCommand::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/action_command/utils.rb

Overview

class with utilities for working with action_commands

Class Method Summary collapse

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:

  1. If item is an object of cls, then returns it

  2. If item is an integer, then assumes its and id and returns cls.find(item)

  3. 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