Sha256: 7deb808beb27719611945601a3f364281897ed061514adc77b25b057913004aa

Contents?: true

Size: 726 Bytes

Versions: 23

Compression:

Stored size: 726 Bytes

Contents

module FavoriteColor
  extend ActiveSupport::Concern

  included do
    validates :operating_thetan, numericality: true, allow_nil: true
    validate :ensure_correct_favorite_color
  end
  
  def ensure_correct_favorite_color
    if favorite_color && (favorite_color != '')
      unless ApplicationHelper::COLOR_NAMES.any?{ |s| s.casecmp(favorite_color)==0 }
        matches = ApplicationHelper::COLOR_SEARCH.search(favorite_color)
        closest_match = matches.last[:string]
        second_closest_match = matches[-2][:string]
        errors.add(:favorite_color, "We've never heard of the color \"#{favorite_color}\". Did you mean \"#{closest_match}\"? Or perhaps \"#{second_closest_match}\"?")
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 7 rubygems

Version Path
devise_token_auth-1.2.4 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth-1.2.2 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth-1.2.1 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth-1.2.0 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth-1.1.5 test/dummy/app/models/concerns/favorite_color.rb
sidecar_token_auth-1.0.1 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth-1.1.4 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth_multitenancy-1.1.3.2 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth_multitenancy-1.1.3.1 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth_multitenancy-1.1.3.alpha1 test/dummy/app/models/concerns/favorite_color.rb
devise_jwt_auth-0.1.5 test/dummy/app/models/concerns/favorite_color.rb
devise_jwt_auth-0.1.4 test/dummy/app/models/concerns/favorite_color.rb
devise_jwt_auth-0.1.3 test/dummy/app/models/concerns/favorite_color.rb
devise_jwt_auth-0.1.2 test/dummy/app/models/concerns/favorite_color.rb
devise_jwt_auth-0.1.1 test/dummy/app/models/concerns/favorite_color.rb
devise_jwt_auth-0.1.0 test/dummy/app/models/concerns/favorite_color.rb
devise-tokens-1.0.4 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth-1.1.3 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth-1.1.2 test/dummy/app/models/concerns/favorite_color.rb
devise_token_auth-1.1.1 test/dummy/app/models/concerns/favorite_color.rb