Module: Shamu::ToModelIdExtension
- Defined in:
- lib/shamu/to_model_id_extension.rb
Overview
Adds to_model_id
to several classes that are often used to look up
models by id.
Defined Under Namespace
Modules: Enumerables, Integers, Models, Strings
Class Method Summary collapse
-
.extend! ⇒ Object
Extend common classes to add
to_model_id
method. -
.model_id?(value) ⇒ Boolean
True if the value looks like an ID.
Class Method Details
.extend! ⇒ Object
Extend common classes to add to_model_id
method.
19 20 21 22 23 24 25 26 |
# 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) ⇒ Boolean
Returns true if the value looks like an ID.
11 12 13 14 15 16 |
# 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 |