Module: KellyLSB::HashId::ClassMethods
- Defined in:
- lib/hashid.rb
Instance Method Summary collapse
Instance Method Details
#hashid(salt) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/hashid.rb', line 156 def hashid(salt) send(:include, Module.new { send(:define_method, :id) do |*args| _id = read_attribute(:id) return _id unless _id.respond_to?(:to_hashid) _id.to_hashid(salt).parameterize end }) send(:extend, Module.new { send(:define_method, :find_by_hashid) do |hashid| hashid = hashid.from_hashid(salt) if hashid.is_a?(String) find(hashid) end }) end |