Skip to content

Commit

Permalink
Version bump (v0.15.0) - No more mongoid support
Browse files Browse the repository at this point in the history
  • Loading branch information
Joost Hietbrink committed Apr 15, 2021
1 parent a8406e4 commit 68d4ca3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
25 changes: 9 additions & 16 deletions README.md
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -114,15 +106,17 @@ In your model use the Phony.plausible method to validate an attribute:
```ruby
validates :phone_number, phony_plausible: true
```

or the helper method:

```ruby
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:

Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/phony_rails/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module PhonyRails
VERSION = '0.14.13'
VERSION = '0.15.0'
end
1 change: 0 additions & 1 deletion phony_rails.gemspec
Expand Up @@ -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'
Expand Down

0 comments on commit 68d4ca3

Please sign in to comment.