From 68d4ca34dc811bd4005ea8266604c769926ae4a0 Mon Sep 17 00:00:00 2001 From: Joost Hietbrink Date: Thu, 15 Apr 2021 13:40:45 +0200 Subject: [PATCH] Version bump (v0.15.0) - No more mongoid support --- README.md | 25 +++++++++---------------- lib/phony_rails/version.rb | 2 +- phony_rails.gemspec | 1 - 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 4dc2f17..2cb44f2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Find version information in the [CHANGELOG](CHANGELOG.md). Add this line to your application's Gemfile (requires Ruby > 2.3): ```ruby -gem 'phony_rails' # Include phony_rails after mongoid (if you use mongoid, see issue #66 on github). +gem 'phony_rails' ``` And then execute: @@ -66,18 +66,10 @@ class SomeModel end ``` -#### Mongoid +#### Mongoid (DEPRECATED) -For **Mongoid**, in keeping with Mongoid plug-in conventions you must include the `Mongoid::Phony` module: +WARNING: From v0.15.0 Mongoid support has been removed! -```ruby -class SomeModel - include Mongoid::Document - include Mongoid::Phony - - # methods are same as ActiveRecord usage -end -``` #### General info The `:default_country_code` options is used to specify a country_code when normalizing. @@ -114,6 +106,7 @@ In your model use the Phony.plausible method to validate an attribute: ```ruby validates :phone_number, phony_plausible: true ``` + or the helper method: ```ruby @@ -121,8 +114,9 @@ validates_plausible_phone :phone_number ``` this method use other validators under the hood to provide: -* presence validation using `ActiveModel::Validations::PresenceValidator` -* format validation using `ActiveModel::Validations::FormatValidator` + +- presence validation using `ActiveModel::Validations::PresenceValidator` +- format validation using `ActiveModel::Validations::FormatValidator` so we can use: @@ -174,11 +168,11 @@ When number is valid, it will save the normalized number (e.g. `+48 888 888 888` #### Allowing records country codes to not match phone number country codes -You may have a record specifying one country (via a `country_code` attribute) but using a phone number from another country. For example, your record may be from Japan but have a phone number from the Philippines. By default, `phony_rails` will consider your record's `country_code` as part of the validation. If that country doesn't match the country code in the phone number, validation will fail. +You may have a record specifying one country (via a `country_code` attribute) but using a phone number from another country. For example, your record may be from Japan but have a phone number from the Philippines. By default, `phony_rails` will consider your record's `country_code` as part of the validation. If that country doesn't match the country code in the phone number, validation will fail. Additionally, `phony_normalize` will always add the records country code as the country number (eg. the user enters '+81xxx' for Japan and the records `country_code` is 'DE' then `phony_normalize` will change the number to '+4981'). You can turn this off by adding `enforce_record_country: false` to the validation options. The country_code will then only be added if no country code is specified. -If you want to allow records from one country to have phone numbers from a different one, there are a couple of options you can use: `ignore_record_country_number` and `ignore_record_country_code`. Use them like so: +If you want to allow records from one country to have phone numbers from a different one, there are a couple of options you can use: `ignore_record_country_number` and `ignore_record_country_code`. Use them like so: ```ruby validates :phone_number, phony_plausible: { ignore_record_country_code: true, ignore_record_country_number: true } @@ -232,7 +226,6 @@ Extensions are supported (identified by "ext", "ex", "x", "xt", "#", or ":") and "+31 (0)30 1234 123 #999".phony_normalized # => '31301234123 x999' ``` - ### Find by normalized number Say you want to find a record by a phone number. Best is to normalize user input and compare to an attribute stored in the db. diff --git a/lib/phony_rails/version.rb b/lib/phony_rails/version.rb index af7bd0e..468a350 100644 --- a/lib/phony_rails/version.rb +++ b/lib/phony_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module PhonyRails - VERSION = '0.14.13' + VERSION = '0.15.0' end diff --git a/phony_rails.gemspec b/phony_rails.gemspec index faa9a37..1ec5a6d 100644 --- a/phony_rails.gemspec +++ b/phony_rails.gemspec @@ -23,7 +23,6 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'activesupport', '>= 3.0' gem.add_runtime_dependency 'phony', '>= 2.18.12' gem.add_development_dependency 'activerecord', '>= 3.0' - # gem.add_development_dependency 'mongoid', '7.1.4' # For testing gem.add_development_dependency 'sqlite3', '>= 1.4.0'