Sha256: 12fb6e9a2f4b5a32a8239cafe526ab746605710797d1dc2ea8a7c9bdd4851f35

Contents?: true

Size: 486 Bytes

Versions: 15

Compression:

Stored size: 486 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
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
action_policy-0.6.7 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.6.6 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.6.5 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.6.4 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.6.3 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.6.2 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.6.1 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.6.0 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.5.7 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.5.6 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.5.5 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.5.4 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.5.3 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.5.2 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.5.1 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb