module Shamu::ToModelIdExtension

Adds `to_model_id` to several classes that are often used to look up models by id.

Public Class Methods

extend!() click to toggle source

Extend common classes to add `to_model_id` method.

# File lib/shamu/to_model_id_extension.rb, line 19
def self.extend!
  Integer.include Integers
  String.include Strings
  Array.include Enumerables
  NilClass.include Integers

  ActiveRecord::Base.include Models if defined? ActiveRecord::Base
end
model_id?( value ) click to toggle source

@param [String,Integer,#to_model_id] value @return [Boolean] true if the value looks like an ID.

# File lib/shamu/to_model_id_extension.rb, line 11
def self.model_id?( value )
  case Array( value ).first
  when Integer then true
  when String  then ToModelIdExtension::Strings::NUMERIC_PATTERN =~ value
  end
end