Sha256: fa318d28a66539de85da6a99a7e133c969ed28e6e8274ecd606c40cc5a171296

Contents?: true

Size: 480 Bytes

Versions: 22

Compression:

Stored size: 480 Bytes

Contents

# frozen_string_literal: true

module ActionPolicy
  # Adds `suggest` method which uses did_you_mean
  # to generate a suggestion message
  module SuggestMessage
    if defined?(::DidYouMean::SpellChecker)
      def suggest(needle, heystack)
        suggestion = ::DidYouMean::SpellChecker.new(
          dictionary: heystack
        ).correct(needle).first

        suggestion ? "\nDid you mean? #{suggestion}" : ""
      end
    else
      def suggest(*) = ""
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
action_policy-0.7.3 lib/action_policy/utils/suggest_message.rb
action_policy-0.7.2 lib/action_policy/utils/suggest_message.rb
action_policy-0.7.1 lib/action_policy/utils/suggest_message.rb
action_policy-0.7.0 lib/action_policy/utils/suggest_message.rb
action_policy-0.6.9 lib/action_policy/utils/suggest_message.rb
action_policy-0.6.8 lib/action_policy/utils/suggest_message.rb
action_policy-0.6.7 lib/action_policy/utils/suggest_message.rb
action_policy-0.6.6 lib/action_policy/utils/suggest_message.rb
action_policy-0.6.5 lib/action_policy/utils/suggest_message.rb
action_policy-0.6.4 lib/action_policy/utils/suggest_message.rb
action_policy-0.6.3 lib/action_policy/utils/suggest_message.rb
action_policy-0.6.2 lib/action_policy/utils/suggest_message.rb
action_policy-0.6.1 lib/action_policy/utils/suggest_message.rb
action_policy-0.6.0 lib/action_policy/utils/suggest_message.rb
action_policy-0.5.7 lib/action_policy/utils/suggest_message.rb
action_policy-0.5.6 lib/action_policy/utils/suggest_message.rb
action_policy-0.5.5 lib/action_policy/utils/suggest_message.rb
action_policy-0.5.4 lib/action_policy/utils/suggest_message.rb
action_policy-0.5.3 lib/action_policy/utils/suggest_message.rb
action_policy-0.5.2 lib/action_policy/utils/suggest_message.rb