phonofy 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab4c944e597b21fd5741b2fe4ae079894b23daef0b1ef5fb02591ea4f9656333
4
- data.tar.gz: ad2f6ae7a63313ab311570c18dd3205cd9026237704cb95daa7b2d48e1e004d5
3
+ metadata.gz: d6ee55367de1d368ab0abacce9dbabf589f6da2a5a8ed458f1541c75f3f26605
4
+ data.tar.gz: 05004a1aa71520d8c5303817ce77891f1062ceed4e42a0e04c45af9d692294c9
5
5
  SHA512:
6
- metadata.gz: 603aadd76e3845d374b472fce743f8bf553605715660a8d7a0926feeca4dd52d1def67bf0254ec433846a55d6722dc13373bd6278308db358d851b3bbb0afec1
7
- data.tar.gz: 19da8320b25ab52c32c8baa4e1603e984b85ae28d1f56250e12e160f7bf9c9951a1ddf02a9b3876e8dcb1b02ec673a12c16242bfbfb067105e8626f7a3fcb62b
6
+ metadata.gz: 0c59eab2f6525b0204123f17b1a7b8a77646ab22820dc8f9d03f17cabfa07eba95fcbb53da2a5b50a751640a629225cf199adbf9a25de39615b139b975a6a115
7
+ data.tar.gz: 69b17995effa660b2b540dff26449a118f206360d4ef9073fc3dc57ccf003342038e71278f7b3fbf3fdf0e4d3ccf172e2be7e168b7e8c09ef3c39d098f3a2e41
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2025-04-24
4
+
5
+ - Added compatibility with Rails 8.0
6
+ - Replaced Rails Engine with Railtie for lighter integration
7
+ - Improved code organization and dependency management
8
+ - Enhanced test coverage for international phone numbers
9
+ - Fixed validator loading
10
+
3
11
  ## [0.1.0] - 2023-03-30
4
12
 
5
13
  - Initial release
data/Gemfile CHANGED
@@ -10,3 +10,8 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
+
14
+ group :test do
15
+ gem "activerecord"
16
+ gem "sqlite3", "~> 2.6"
17
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phonofy (0.1.1)
4
+ phonofy (0.2.0)
5
5
  activerecord
6
6
  i18n
7
7
  phonelib
@@ -9,30 +9,178 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (7.0.4)
13
- activesupport (= 7.0.4)
14
- activerecord (7.0.4)
15
- activemodel (= 7.0.4)
16
- activesupport (= 7.0.4)
17
- activesupport (7.0.4)
18
- concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ actioncable (8.0.2)
13
+ actionpack (= 8.0.2)
14
+ activesupport (= 8.0.2)
15
+ nio4r (~> 2.0)
16
+ websocket-driver (>= 0.6.1)
17
+ zeitwerk (~> 2.6)
18
+ actionmailbox (8.0.2)
19
+ actionpack (= 8.0.2)
20
+ activejob (= 8.0.2)
21
+ activerecord (= 8.0.2)
22
+ activestorage (= 8.0.2)
23
+ activesupport (= 8.0.2)
24
+ mail (>= 2.8.0)
25
+ actionmailer (8.0.2)
26
+ actionpack (= 8.0.2)
27
+ actionview (= 8.0.2)
28
+ activejob (= 8.0.2)
29
+ activesupport (= 8.0.2)
30
+ mail (>= 2.8.0)
31
+ rails-dom-testing (~> 2.2)
32
+ actionpack (8.0.2)
33
+ actionview (= 8.0.2)
34
+ activesupport (= 8.0.2)
35
+ nokogiri (>= 1.8.5)
36
+ rack (>= 2.2.4)
37
+ rack-session (>= 1.0.1)
38
+ rack-test (>= 0.6.3)
39
+ rails-dom-testing (~> 2.2)
40
+ rails-html-sanitizer (~> 1.6)
41
+ useragent (~> 0.16)
42
+ actiontext (8.0.2)
43
+ actionpack (= 8.0.2)
44
+ activerecord (= 8.0.2)
45
+ activestorage (= 8.0.2)
46
+ activesupport (= 8.0.2)
47
+ globalid (>= 0.6.0)
48
+ nokogiri (>= 1.8.5)
49
+ actionview (8.0.2)
50
+ activesupport (= 8.0.2)
51
+ builder (~> 3.1)
52
+ erubi (~> 1.11)
53
+ rails-dom-testing (~> 2.2)
54
+ rails-html-sanitizer (~> 1.6)
55
+ activejob (8.0.2)
56
+ activesupport (= 8.0.2)
57
+ globalid (>= 0.3.6)
58
+ activemodel (8.0.2)
59
+ activesupport (= 8.0.2)
60
+ activerecord (8.0.2)
61
+ activemodel (= 8.0.2)
62
+ activesupport (= 8.0.2)
63
+ timeout (>= 0.4.0)
64
+ activestorage (8.0.2)
65
+ actionpack (= 8.0.2)
66
+ activejob (= 8.0.2)
67
+ activerecord (= 8.0.2)
68
+ activesupport (= 8.0.2)
69
+ marcel (~> 1.0)
70
+ activesupport (8.0.2)
71
+ base64
72
+ benchmark (>= 0.3)
73
+ bigdecimal
74
+ concurrent-ruby (~> 1.0, >= 1.3.1)
75
+ connection_pool (>= 2.2.5)
76
+ drb
19
77
  i18n (>= 1.6, < 2)
78
+ logger (>= 1.4.2)
20
79
  minitest (>= 5.1)
21
- tzinfo (~> 2.0)
80
+ securerandom (>= 0.3)
81
+ tzinfo (~> 2.0, >= 2.0.5)
82
+ uri (>= 0.13.1)
22
83
  ast (2.4.2)
23
- concurrent-ruby (1.2.2)
84
+ base64 (0.2.0)
85
+ benchmark (0.4.0)
86
+ bigdecimal (3.1.9)
87
+ builder (3.3.0)
88
+ concurrent-ruby (1.3.5)
89
+ connection_pool (2.5.1)
90
+ crass (1.0.6)
91
+ date (3.4.1)
24
92
  diff-lcs (1.5.0)
93
+ drb (2.2.1)
94
+ erubi (1.13.1)
95
+ globalid (1.2.1)
96
+ activesupport (>= 6.1)
25
97
  i18n (1.12.0)
26
98
  concurrent-ruby (~> 1.0)
99
+ io-console (0.8.0)
100
+ irb (1.15.2)
101
+ pp (>= 0.6.0)
102
+ rdoc (>= 4.0.0)
103
+ reline (>= 0.4.2)
27
104
  json (2.6.3)
105
+ logger (1.7.0)
106
+ loofah (2.24.0)
107
+ crass (~> 1.0.2)
108
+ nokogiri (>= 1.12.0)
109
+ mail (2.8.1)
110
+ mini_mime (>= 0.1.1)
111
+ net-imap
112
+ net-pop
113
+ net-smtp
114
+ marcel (1.0.4)
115
+ mini_mime (1.1.5)
28
116
  minitest (5.18.0)
117
+ net-imap (0.5.6)
118
+ date
119
+ net-protocol
120
+ net-pop (0.1.2)
121
+ net-protocol
122
+ net-protocol (0.2.2)
123
+ timeout
124
+ net-smtp (0.5.1)
125
+ net-protocol
126
+ nio4r (2.7.4)
127
+ nokogiri (1.18.7-arm64-darwin)
128
+ racc (~> 1.4)
29
129
  parallel (1.22.1)
30
130
  parser (3.2.1.1)
31
131
  ast (~> 2.4.1)
32
132
  phonelib (0.7.7)
133
+ pp (0.6.2)
134
+ prettyprint
135
+ prettyprint (0.2.0)
136
+ psych (5.2.3)
137
+ date
138
+ stringio
139
+ racc (1.8.1)
140
+ rack (3.1.13)
141
+ rack-session (2.1.0)
142
+ base64 (>= 0.1.0)
143
+ rack (>= 3.0.0)
144
+ rack-test (2.2.0)
145
+ rack (>= 1.3)
146
+ rackup (2.2.1)
147
+ rack (>= 3)
148
+ rails (8.0.2)
149
+ actioncable (= 8.0.2)
150
+ actionmailbox (= 8.0.2)
151
+ actionmailer (= 8.0.2)
152
+ actionpack (= 8.0.2)
153
+ actiontext (= 8.0.2)
154
+ actionview (= 8.0.2)
155
+ activejob (= 8.0.2)
156
+ activemodel (= 8.0.2)
157
+ activerecord (= 8.0.2)
158
+ activestorage (= 8.0.2)
159
+ activesupport (= 8.0.2)
160
+ bundler (>= 1.15.0)
161
+ railties (= 8.0.2)
162
+ rails-dom-testing (2.2.0)
163
+ activesupport (>= 5.0.0)
164
+ minitest
165
+ nokogiri (>= 1.6)
166
+ rails-html-sanitizer (1.6.2)
167
+ loofah (~> 2.21)
168
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
169
+ railties (8.0.2)
170
+ actionpack (= 8.0.2)
171
+ activesupport (= 8.0.2)
172
+ irb (~> 1.13)
173
+ rackup (>= 1.0.0)
174
+ rake (>= 12.2)
175
+ thor (~> 1.0, >= 1.2.2)
176
+ zeitwerk (~> 2.6)
33
177
  rainbow (3.1.1)
34
178
  rake (13.0.6)
179
+ rdoc (6.13.1)
180
+ psych (>= 4.0.0)
35
181
  regexp_parser (2.7.0)
182
+ reline (0.6.1)
183
+ io-console (~> 0.5)
36
184
  rexml (3.2.5)
37
185
  rspec (3.12.0)
38
186
  rspec-core (~> 3.12.0)
@@ -60,18 +208,34 @@ GEM
60
208
  rubocop-ast (1.28.0)
61
209
  parser (>= 3.2.1.0)
62
210
  ruby-progressbar (1.13.0)
211
+ securerandom (0.4.1)
212
+ sqlite3 (2.6.0-arm64-darwin)
213
+ stringio (3.1.6)
214
+ thor (1.3.2)
215
+ timeout (0.4.3)
63
216
  tzinfo (2.0.6)
64
217
  concurrent-ruby (~> 1.0)
65
218
  unicode-display_width (2.4.2)
219
+ uri (1.0.3)
220
+ useragent (0.16.11)
221
+ websocket-driver (0.7.7)
222
+ base64
223
+ websocket-extensions (>= 0.1.0)
224
+ websocket-extensions (0.1.5)
225
+ zeitwerk (2.7.2)
66
226
 
67
227
  PLATFORMS
68
228
  arm64-darwin-22
229
+ arm64-darwin-24
69
230
 
70
231
  DEPENDENCIES
232
+ activerecord
71
233
  phonofy!
234
+ rails (>= 6.0, < 9.0)
72
235
  rake (~> 13.0)
73
236
  rspec (~> 3.0)
74
237
  rubocop (~> 1.21)
238
+ sqlite3 (~> 2.6)
75
239
 
76
240
  BUNDLED WITH
77
241
  2.4.10
data/README.md CHANGED
@@ -1,44 +1,100 @@
1
1
  # Phonofy
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/phonofy`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Phonofy is a Ruby gem that simplifies phone number formatting in Ruby applications using the Phonelib library. It integrates seamlessly with Rails applications (compatible with Rails 6.0 through 8.0) but can also be used in non-Rails environments. With Phonofy, you can easily parse and format phone number data according to international standards, ensuring that your phone number data is consistent and valid across your application.
6
4
 
7
5
  ## Installation
8
6
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'phonofy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```shell
16
+ bundle
17
+ ```
10
18
 
11
- Install the gem and add to the application's Gemfile by executing:
19
+ Or install it yourself as:
20
+
21
+ ```shell
22
+ gem install phonofy
23
+ ```
24
+
25
+ ## **Usage**
26
+ To use phonofy, simply call the **phonofy** method in your Rails model:
27
+
28
+ ```ruby
29
+ class User < ApplicationRecord
30
+ phonofy
31
+ end
32
+ ```
12
33
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
34
+ This will add phone number validation and formatting to the **phone_number** attribute of the **User** model.
14
35
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
36
+ You can also specify a custom attribute name for the phone number:
16
37
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
38
+ ```ruby
39
+ class Contact < ApplicationRecord
40
+ phonofy :mobile_number
41
+ end
42
+ ```
18
43
 
19
- ## Usage
44
+ This will add phone number validation and formatting to the **mobile_number** attribute of the **Contact** model.
20
45
 
21
- TODO: Write usage instructions here
46
+ You can also pass additional options to phonofy to customize its behavior:
22
47
 
23
- To access configs:
48
+ ```ruby
49
+ class User < ApplicationRecord
50
+ phonofy :phone, phonelib: { countries: [:us, :ca], types: [:mobile] }
51
+ end
24
52
  ```
25
- User.phonofy_configs
53
+
54
+ This will add phone number validation and formatting to the **phone** attribute of the **User** model, and restrict it to US and Canada mobile phone numbers.
55
+
56
+
57
+ ## **Configuration**
58
+
59
+ You can configure phonofy by creating an initializer file in your Rails application and setting the default options:
60
+
61
+ ```ruby
62
+ # config/initializers/phonofy.rb
63
+ Phonofy.configure do |config|
64
+ config.default_phonelib_options = { countries: [:us, :ca], types: [:mobile] }
65
+ end
26
66
  ```
27
67
 
28
- ## Development
68
+ This will set the default options for phonofy to validate only US and Canada mobile phone numbers using the Phonelib library.
29
69
 
30
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
70
+ ## **International Phone Number Support**
31
71
 
32
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
72
+ Phonofy supports international phone numbers through the Phonelib gem. You can validate and format phone numbers for specific countries by including the country codes in the countries option:
73
+
74
+ ```ruby
75
+ class User < ApplicationRecord
76
+ phonofy :phone, phonelib: { countries: [:us, :gb, :fr] }
77
+ end
78
+ ```
79
+
80
+ Example usage:
81
+
82
+ ```ruby
83
+ user = User.new(phone: "+14155552671")
84
+ user.phone(:e164) # => "+14155552671"
85
+ user.phone(:international) # => "+1 415-555-2671"
86
+ user.phone(:national) # => "(415) 555-2671"
87
+ user.phone_is_valid? # => true
88
+ ```
33
89
 
34
- ## Contributing
90
+ ## **Contributing**
35
91
 
36
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/phonofy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/phonofy/blob/main/CODE_OF_CONDUCT.md).
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shqear93/phonofy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org/) code of conduct.
37
93
 
38
- ## License
94
+ ## **License**
39
95
 
40
96
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
97
 
42
- ## Code of Conduct
98
+ ## **Credits**
43
99
 
44
- Everyone interacting in the Phonofy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/phonofy/blob/main/CODE_OF_CONDUCT.md).
100
+ phonofy was created by Khaled AbuShqear and is maintained by a community of contributors.
data/README.md.erb CHANGED
@@ -1,13 +1,13 @@
1
- # <%= gem_name.capitalize %>
1
+ # <%= spec.name.capitalize %>
2
2
 
3
- <%= gem_description %>
3
+ <%= spec.description %>
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem '<%= gem_name %>'
10
+ gem '<%= spec.name %>'
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -19,11 +19,11 @@ bundle
19
19
  Or install it yourself as:
20
20
 
21
21
  ```shell
22
- gem install <%= gem_name %>
22
+ gem install <%= spec.name %>
23
23
  ```
24
24
 
25
25
  ## **Usage**
26
- To use <%= gem_name %>, simply call the **phonofy** method in your Rails model:
26
+ To use <%= spec.name %>, simply call the **phonofy** method in your Rails model:
27
27
 
28
28
  ```ruby
29
29
  class User < ApplicationRecord
@@ -43,7 +43,7 @@ end
43
43
 
44
44
  This will add phone number validation and formatting to the **mobile_number** attribute of the **Contact** model.
45
45
 
46
- You can also pass additional options to <%= gem_name %> to customize its behavior:
46
+ You can also pass additional options to <%= spec.name %> to customize its behavior:
47
47
 
48
48
  ```ruby
49
49
  class User < ApplicationRecord
@@ -56,21 +56,21 @@ This will add phone number validation and formatting to the **phone** attribute
56
56
 
57
57
  ## **Configuration**
58
58
 
59
- You can configure <%= gem_name %> by creating an initializer file in your Rails application and setting the default options:
59
+ You can configure <%= spec.name %> by creating an initializer file in your Rails application and setting the default options:
60
60
 
61
61
  ```ruby
62
- # config/initializers/<%= gem_name %>.rb
63
- <%= gem_module %>.configure do |config|
62
+ # config/initializers/<%= spec.name %>.rb
63
+ <%= spec.name.capitalize %>.configure do |config|
64
64
  config.default_phonelib_options = { countries: [:us, :ca], types: [:mobile] }
65
65
  config.default_twilio_options = { lookup: { type: :carrier_type } }
66
66
  end
67
67
  ```
68
68
 
69
- This will set the default options for <%= gem_name %> to validate only US and Canada mobile phone numbers using the Phonelib library, and perform a Twilio lookup to get carrier information for the phone number.
69
+ This will set the default options for <%= spec.name %> to validate only US and Canada mobile phone numbers using the Phonelib library, and perform a Twilio lookup to get carrier information for the phone number.
70
70
 
71
71
  ## **Contributing**
72
72
 
73
- Bug reports and pull requests are welcome on GitHub at <%= github_url %>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org/) code of conduct.
73
+ Bug reports and pull requests are welcome on GitHub at <%= spec.metadata["source_code_uri"] %>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org/) code of conduct.
74
74
 
75
75
  ## **License**
76
76
 
@@ -78,4 +78,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
78
78
 
79
79
  ## **Credits**
80
80
 
81
- <%= gem_name %> was created by <%= author_name %> and is maintained by a community of contributors.
81
+ <%= spec.name %> was created by <%= spec.authors.first %> and is maintained by a community of contributors.
data/Rakefile CHANGED
@@ -12,11 +12,12 @@ RuboCop::RakeTask.new
12
12
  task default: %i[spec rubocop]
13
13
 
14
14
  require "erb"
15
+ spec = Gem::Specification.load("phonofy.gemspec")
15
16
 
16
17
  desc "Generate README.md from template"
17
18
  task :readme do
18
19
  template = File.read("README.md.erb")
19
- readme = ERB.new(template).result(binding)
20
+ readme = ERB.new(template).result_with_hash({ spec: spec })
20
21
  File.write("README.md", readme)
21
22
  end
22
23
 
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
- # require_relative "phonofy/fy/version"
3
2
 
4
3
  module Phonofy
5
4
  module Model
6
5
  module ClassMethods
7
-
8
- DEFAULTS = { phonelib: { allow_blank: true, validation_options: {} } }.freeze
6
+ DEFAULTS = {
7
+ phonelib: {
8
+ allow_blank: true,
9
+ validation_options: {}
10
+ }
11
+ }.deep_merge(Phonofy.config.default_phonelib_options || {}).freeze
9
12
 
10
13
  def phonofy(column_name = :phone_number, **options)
11
14
  options = DEFAULTS.deep_merge(options)
@@ -15,7 +18,7 @@ module Phonofy
15
18
  self.phonofy_configs = { _counter: {} }
16
19
  end
17
20
 
18
- counter = (phonofy_configs[:_counter][column_name] ||= 0)
21
+ counter = (phonofy_configs[:_counter][column_name] ||= 0)
19
22
  phonofy_configs[:_counter][column_name] += 1
20
23
 
21
24
  phonofy_configs["#{column_name}_#{counter}"] = options.dup
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phonofy
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/phonofy.rb CHANGED
@@ -1,22 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "phonofy/version"
4
-
5
- require "active_record"
6
- require "model/instance_dynamic_methods"
7
4
  require "phonelib"
8
- require "model"
9
5
 
10
6
  module Phonofy
11
7
  class Error < StandardError; end
12
8
 
13
- class Engine < ::Rails::Engine
14
- initializer "phonofy.initialize" do
15
- ActiveSupport.on_load(:active_record) do
16
- include Phonofy::Model
17
- end
9
+ class << self
10
+ attr_accessor :configuration
11
+ end
12
+
13
+ def self.configure
14
+ self.configuration ||= Configuration.new
15
+ yield(configuration)
16
+ end
17
+
18
+ def self.config
19
+ configuration
20
+ end
21
+
22
+ class Configuration
23
+ attr_accessor :default_phonelib_options
18
24
 
19
- config.i18n.load_path += Dir[config.root.join("config", "locales", "**", "*.{rb,yml}")]
25
+ def initialize
26
+ @default_phonelib_options = {}
20
27
  end
21
28
  end
29
+
30
+ # Initialize default configuration
31
+ self.configuration = Configuration.new
22
32
  end
33
+
34
+ # Load ActiveRecord-related code
35
+ require "active_record"
36
+ require_relative "model/instance_dynamic_methods"
37
+ require_relative "model"
38
+
39
+ # Only load the Railtie if Rails is available
40
+ if defined?(Rails)
41
+ require_relative "railtie"
42
+ end
43
+
44
+ # Model is already required above
data/lib/railtie.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "pathname"
5
+ require_relative "model"
6
+
7
+ module Phonofy
8
+ class Railtie < Rails::Railtie
9
+ initializer "phonofy.initialize" do
10
+ ActiveSupport.on_load(:active_record) do
11
+ include Phonofy::Model
12
+ end
13
+ end
14
+
15
+ initializer "phonofy.load_translations" do
16
+ # Use Rails.root if available, otherwise use the gem's path
17
+ if defined?(Rails.root) && Rails.root
18
+ config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**", "*.{rb,yml}")]
19
+ else
20
+ # Fallback to the gem's own translations
21
+ gem_root = Pathname.new(File.expand_path("../", __dir__))
22
+ config.i18n.load_path += Dir[gem_root.join("config", "locales", "**", "*.{rb,yml}")]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "../validators"
4
4
  require "#{Gem::Specification.find_by_name("phonelib").gem_dir}/lib/validators/phone_validator"
5
+ require "active_model/version"
5
6
 
6
7
  module Phonofy
7
8
  module Validators
@@ -13,7 +14,16 @@ module Phonofy
13
14
  valid = countries.present? ? valid_country? : phone_valid?
14
15
  valid = valid && valid_types? && valid_extensions?
15
16
 
16
- record.errors.add(attribute, message(error_message), options) unless valid
17
+ unless valid
18
+ # Rails 8.0+ compatibility - errors.add no longer accepts options as a third argument
19
+ if ActiveModel.version >= Gem::Version.new('8.0.0')
20
+ # For Rails 8.0+, use the new API
21
+ record.errors.add(attribute, message(error_message), **options)
22
+ else
23
+ # For older Rails versions, use the old API
24
+ record.errors.add(attribute, message(error_message), options)
25
+ end
26
+ end
17
27
  end
18
28
 
19
29
  private
@@ -0,0 +1,7 @@
1
+ module Phonofy
2
+ class Configuration
3
+ attr_accessor default_phonelib_options: Hash[Symbol, untyped]
4
+
5
+ def initialize: () -> void
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module Phonofy
2
+ module Model
3
+ module ClassMethods
4
+ DEFAULTS: Hash[Symbol, untyped]
5
+
6
+ def phonofy: (?Symbol column_name, **untyped options) -> void
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Phonofy
2
+ module Model
3
+ class InstanceDynamicMethods < Module
4
+ DEFAULT_PHONE_FORMAT: Symbol
5
+ SUPPORTED_FORMATS: Array[Symbol]
6
+
7
+ def initialize: (Symbol column_name, Hash[Symbol, untyped] options) -> void
8
+ def included: (Class base) -> void
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Phonofy
2
+ module Model
3
+ def self.included: (Class base) -> void
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Phonofy
2
+ class Railtie < Rails::Railtie
3
+ # No need to define initializers in RBS
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ module Phonofy
2
+ module Validators
3
+ class ExtendedPhoneValidator < PhoneValidator
4
+ def validate_each: (untyped record, Symbol attribute, untyped value) -> void
5
+ def check_rails_version: () -> bool
6
+
7
+ private
8
+
9
+ def message: (?Symbol custom) -> Symbol
10
+
11
+ def error_message: () -> Symbol
12
+
13
+ def valid_country?: () -> bool
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ module Phonofy
2
+ module Validators
3
+ end
4
+ end
data/sig/phonofy.rbs CHANGED
@@ -1,4 +1,15 @@
1
1
  module Phonofy
2
2
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
3
+
4
+ class Error < StandardError
5
+ end
6
+
7
+ class << self
8
+ attr_accessor configuration: Configuration
9
+ end
10
+
11
+ # These methods are already defined by the attr_accessor above
12
+
13
+ def self.configure: () { (Configuration) -> void } -> void
14
+ def self.config: () -> Configuration
4
15
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phonofy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khaled AbuShqear
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-04-02 00:00:00.000000000 Z
10
+ date: 2025-04-23 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: i18n
@@ -52,10 +51,31 @@ dependencies:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
- description: Phonofy is a Ruby gem that simplifies phone number formatting in Rails
56
- applications using the Phonelib library. With Phonofy, you can easily parse and
57
- format phone number data according to international standards, ensuring that your
58
- phone number data is consistent and valid across your application.
54
+ - !ruby/object:Gem::Dependency
55
+ name: rails
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '6.0'
61
+ - - "<"
62
+ - !ruby/object:Gem::Version
63
+ version: '9.0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '6.0'
71
+ - - "<"
72
+ - !ruby/object:Gem::Version
73
+ version: '9.0'
74
+ description: Phonofy is a Ruby gem that simplifies phone number formatting in Ruby
75
+ applications using the Phonelib library. It integrates seamlessly with Rails applications
76
+ but can also be used in non-Rails environments. With Phonofy, you can easily parse
77
+ and format phone number data according to international standards, ensuring that
78
+ your phone number data is consistent and valid across your application.
59
79
  email:
60
80
  - qmax93@gmail.com
61
81
  executables: []
@@ -78,9 +98,17 @@ files:
78
98
  - lib/model/instance_dynamic_methods.rb
79
99
  - lib/phonofy.rb
80
100
  - lib/phonofy/version.rb
101
+ - lib/railtie.rb
81
102
  - lib/validators.rb
82
103
  - lib/validators/extended_phone_validator.rb
83
104
  - sig/phonofy.rbs
105
+ - sig/phonofy/configuration.rbs
106
+ - sig/phonofy/model.rbs
107
+ - sig/phonofy/model/class_methods.rbs
108
+ - sig/phonofy/model/instance_dynamic_methods.rbs
109
+ - sig/phonofy/railtie.rbs
110
+ - sig/phonofy/validators.rbs
111
+ - sig/phonofy/validators/extended_phone_validator.rbs
84
112
  homepage: https://github.com/shqear93/phonofy
85
113
  licenses:
86
114
  - MIT
@@ -88,7 +116,6 @@ metadata:
88
116
  homepage_uri: https://github.com/shqear93/phonofy
89
117
  source_code_uri: https://github.com/shqear93/phonofy
90
118
  changelog_uri: https://github.com/shqear93/phonofy/blob/master/CHANGELOG.md
91
- post_install_message:
92
119
  rdoc_options: []
93
120
  require_paths:
94
121
  - lib
@@ -103,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
130
  - !ruby/object:Gem::Version
104
131
  version: '0'
105
132
  requirements: []
106
- rubygems_version: 3.4.10
107
- signing_key:
133
+ rubygems_version: 3.6.2
108
134
  specification_version: 4
109
- summary: Phonofy integrates with rails ActiveRecord to provide formatting functionalities.
135
+ summary: Phonofy integrates with ActiveRecord to provide phone number formatting functionalities.
110
136
  test_files: []