class SlugFu::ModelContext
Context that can be used with ActiveRecord models to check if a slug already exists in a given scope.
Example:
SlugFu(str, context: SlugFu::ModelContext.new
(Book, :url_slug))
Public Class Methods
new(scope, attr = :slug)
click to toggle source
# File lib/slug_fu/model_context.rb, line 10 def initialize(scope, attr = :slug) @scope = scope @attr = attr freeze end
Public Instance Methods
include?(value)
click to toggle source
# File lib/slug_fu/model_context.rb, line 16 def include?(value) @scope.exists?(@attr => value) end