Module: Sequel::Plugins::HashId
- Defined in:
- lib/sequel/plugins/hash_id.rb
Overview
This plugin allows you to easily obscure the primary key of your models with an encoded hashid equivalent.
A few convenience methods are provided which wrap around the Hashids library.
Plugin Options
- :salt
-
The salt used to hash/unhash the primary key values. Required.
- :length
-
By default, the length is variable. Setting an integer here forces all hashids to be a specific length.
Defined Under Namespace
Modules: ClassMethods, DatasetMethods, InstanceMethods
Class Method Summary collapse
-
.apply(model, opts = {}) ⇒ Object
:nodoc:.
-
.configure(model, opts = {}) ⇒ Object
:nodoc:.
Class Method Details
.apply(model, opts = {}) ⇒ Object
:nodoc:
15 16 17 18 19 |
# File 'lib/sequel/plugins/hash_id.rb', line 15 def self.apply(model, opts = {}) # :nodoc: model.instance_eval do @hash_id_state = {} end end |
.configure(model, opts = {}) ⇒ Object
:nodoc:
21 22 23 24 25 26 |
# File 'lib/sequel/plugins/hash_id.rb', line 21 def self.configure(model, opts = {}) # :nodoc: model.instance_eval do @hash_id_state[:salt] = opts[:salt] || raise(ArgumentError, "hash_id plugin missing salt option") @hash_id_state[:length] = opts[:length] || 0 end end |