class ActionCommand::Utils

class with utilities for working with action_commands

Public Class Methods

find_id(cls, item) { |item| ... } click to toggle source

Used for cases where you might have a active record object, or an integer id, or some kind of string identifier. If it is an active record object, this will return its id. If it is an integer, it will return it. Otherwise, it will pass the string to yield, which can lookup the object

# File lib/action_command/utils.rb, line 23
def self.find_id(cls, item)
  return item.id if item.is_a? cls
  return item if item.is_a? Integer
  return yield(item)
end
find_object(cls, item) { |item| ... } click to toggle source

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.

# 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