Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ default options.
Hashid::Rails.configure do |config|
# The salt to use for generating hashid. Prepended with pepper (table name).
config.salt = ""
config.pepper = table_name
config.pepper = ->(klass) { klass.table_name }

# The minimum length of generated hashids
config.min_hash_length = 6
Expand Down
Empty file modified bin/setup
100644 → 100755
Empty file.
7 changes: 6 additions & 1 deletion lib/hashid/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ def to_param
module ClassMethods
def hashid_config(options = {})
config = Hashid::Rails.configuration.dup
config.pepper = table_name

options.each do |attr, value|
config.public_send("#{attr}=", value)
end

if config.pepper.respond_to?(:call)
config.pepper = config.pepper.call(self)
end

@hashid_configuration = config
end

Expand Down
2 changes: 1 addition & 1 deletion lib/hashid/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Configuration

def initialize
@salt = ""
@pepper = ""
@pepper = ->(klass) { klass.table_name }
@min_hash_length = 6
@alphabet = "abcdefghijklmnopqrstuvwxyz" \
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
Expand Down
2 changes: 1 addition & 1 deletion spec/hashid/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@
config = Hashid::Rails.configuration
aggregate_failures "default config" do
expect(config.salt).to eq("")
expect(config.pepper).to eq("")
expect(config.pepper).to a_kind_of(Proc)
expect(config.min_hash_length).to eq(6)
expect(config.alphabet).to eq(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
Expand Down