has_contact_number 0.1.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 +7 -0
- data/.editorconfig +9 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +93 -0
- data/Rakefile +7 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/has_contact_number.gemspec +30 -0
- data/lib/has_contact_number/controller_methods.rb +9 -0
- data/lib/has_contact_number/helper_methods.rb +13 -0
- data/lib/has_contact_number/model_methods.rb +43 -0
- data/lib/has_contact_number/version.rb +6 -0
- data/lib/has_contact_number.rb +10 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ffbc27af06a9ce3aa4bba728fd3fd108916f5503
|
4
|
+
data.tar.gz: 5729a354b6244a8d56f1a042dd2fe13ba163a59a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 387dd6edce276bb6af1fa9e9e1156df4e85211a408488984bb79f2bae95f5403546dc07fb339eec77dd6430c8b751e48ba2aafa6a674072d81990b9bf1aa80ff
|
7
|
+
data.tar.gz: 58f1bf86989806033a3850e4eab3f5c223a3a0eda89d0974925f5d6394956b85295011983e2179defbb2bc3af759cfb858afd47305a315a6e6ff684c5c1e0282
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at anand.bait@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Anand Bait
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# HasContactNumber
|
2
|
+
|
3
|
+
Provides support for validating, storing and retrieving phone, mobile, fax numbers with ISD code.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'has_contact_number'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```shell
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Prerequisites
|
22
|
+
|
23
|
+
Add columns for required contact_number attributes in table.
|
24
|
+
|
25
|
+
### In Model
|
26
|
+
|
27
|
+
Define contact number attributes/columns in model where you have columns like phone_number, mobile_number, fax_number, etc.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
contact_number_attributes :column1, :column2, :columnN
|
31
|
+
```
|
32
|
+
For example:
|
33
|
+
```ruby
|
34
|
+
class Contact < ActiveRecord::Base
|
35
|
+
|
36
|
+
contact_number_attributes :phone_number, :mobile_number, :fax_number
|
37
|
+
|
38
|
+
end
|
39
|
+
```
|
40
|
+
### In Controller
|
41
|
+
|
42
|
+
Use method contact_number_attributes to generate list of attributes to be permitted.
|
43
|
+
|
44
|
+
For example:
|
45
|
+
```ruby
|
46
|
+
class ContactsController < ApplicationController
|
47
|
+
|
48
|
+
def contact_params
|
49
|
+
params.require(:contact).permit(
|
50
|
+
*contact_number_attributes(:phone_number, :mobile_number, :fax_number), # Other attributes
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
```
|
56
|
+
Note: Pay attention to usage of splat operator (`*`) prefixed to contact_number_attributes
|
57
|
+
|
58
|
+
### In View
|
59
|
+
|
60
|
+
You can add select list for ISD code of contact_number attribute using collection options_for_isd_code_select and text field for contact_number attribute.
|
61
|
+
|
62
|
+
For example:
|
63
|
+
If you have phone_number attribute then following should be your view code (For HAML)
|
64
|
+
```haml
|
65
|
+
= f.select :phone_number_isd_code, options_for_isd_code_select, prompt: 'Select'
|
66
|
+
= f.text_field :phone_number_without_isd_code, placeholder: 'Phone Number'
|
67
|
+
```
|
68
|
+
|
69
|
+
You can use any FormBuilder like SimpleForm as
|
70
|
+
|
71
|
+
```haml
|
72
|
+
= f.input :phone_number_isd_code, collection: options_for_isd_code_select, prompt: 'Select'
|
73
|
+
= f.input :phone_number_without_isd_code, placeholder: 'Phone Number'
|
74
|
+
```
|
75
|
+
|
76
|
+
|
77
|
+
## TODOs
|
78
|
+
|
79
|
+
* Helper methods for generating fields on view
|
80
|
+
* Field helper methods with Bootstrap, Foundation support
|
81
|
+
* Method to format contact number as per default pattern
|
82
|
+
* Method to format contact number as per country of ISD code
|
83
|
+
* Method to format number as per custom pattern passed
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/has_contact_number. 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.
|
88
|
+
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
93
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'has_contact_number'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
4
|
+
require 'has_contact_number/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
|
8
|
+
spec.name = 'has_contact_number'
|
9
|
+
spec.version = HasContactNumber::VERSION
|
10
|
+
spec.authors = ['Anand Bait']
|
11
|
+
spec.email = ['anand.bait@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Phone, mobile, fax numbers with ISD code storage and validation.'
|
14
|
+
spec.description = 'Provides support for validating, storing and retrieving phone, mobile, fax numbers with ISD code.'
|
15
|
+
spec.homepage = 'https://github.com/AquisTech/has_contact_number'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_dependency 'iso_country_codes'
|
24
|
+
spec.add_dependency 'phony_rails'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module HasContactNumber::ControllerMethods
|
3
|
+
|
4
|
+
def contact_number_attributes(*attrs)
|
5
|
+
attrs.flat_map { |attr| [:"#{attr}_isd_code", :"#{attr}_without_isd_code"] }
|
6
|
+
end
|
7
|
+
|
8
|
+
end
|
9
|
+
ActionController::Base.send(:include, HasContactNumber::ControllerMethods)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ActionView::Helpers::FormOptionsHelper
|
3
|
+
|
4
|
+
puts '------------------------------------HasContactNumber::HelperMethods---------------------'
|
5
|
+
def options_for_isd_code_select
|
6
|
+
@isd_code_options ||= IsoCountryCodes.all.map do |record|
|
7
|
+
|
8
|
+
[record.calling_code, record.calling_code.delete('+').rjust(4, '0')]
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module HasContactNumber::ModelMethods
|
3
|
+
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
puts '---------------------HasContactNumber::ModelMethods---------------------'
|
6
|
+
module ClassMethods
|
7
|
+
|
8
|
+
def contact_number_attributes(*columns)
|
9
|
+
columns.each do |column|
|
10
|
+
|
11
|
+
define_methods_for(column)
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def define_methods_for(column)
|
17
|
+
class_eval <<-METHODS
|
18
|
+
attr_accessor :#{column}_isd_code, :#{column}_without_isd_code
|
19
|
+
|
20
|
+
def #{column}_isd_code
|
21
|
+
@#{column}_isd_code ||= #{column} && #{column}[0..3]
|
22
|
+
end
|
23
|
+
|
24
|
+
def #{column}_without_isd_code
|
25
|
+
@#{column}_without_isd_code ||= #{column} && #{column}[4..-1]
|
26
|
+
end
|
27
|
+
|
28
|
+
before_validation { |model|
|
29
|
+
model.#{column} = model.#{column}_isd_code + model.#{column}_without_isd_code
|
30
|
+
}
|
31
|
+
|
32
|
+
validates :#{column}_isd_code, presence: true, if: '#{column}_without_isd_code.present?'
|
33
|
+
validates :#{column}_without_isd_code, presence: true, if: '#{column}_isd_code.present?'
|
34
|
+
validates :#{column}, phony_plausible: true, if: proc { |model|
|
35
|
+
model.#{column}_isd_code.present? && model.#{column}_without_isd_code.present?
|
36
|
+
}
|
37
|
+
METHODS
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
ActiveRecord::Base.send(:include, HasContactNumber::ModelMethods)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'has_contact_number/version'
|
3
|
+
require 'phony_rails'
|
4
|
+
require 'iso_country_codes'
|
5
|
+
require 'has_contact_number/model_methods'
|
6
|
+
require 'has_contact_number/controller_methods'
|
7
|
+
require 'has_contact_number/helper_methods'
|
8
|
+
|
9
|
+
module HasContactNumber
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: has_contact_number
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anand Bait
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: iso_country_codes
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: phony_rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Provides support for validating, storing and retrieving phone, mobile,
|
84
|
+
fax numbers with ISD code.
|
85
|
+
email:
|
86
|
+
- anand.bait@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".editorconfig"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- has_contact_number.gemspec
|
103
|
+
- lib/has_contact_number.rb
|
104
|
+
- lib/has_contact_number/controller_methods.rb
|
105
|
+
- lib/has_contact_number/helper_methods.rb
|
106
|
+
- lib/has_contact_number/model_methods.rb
|
107
|
+
- lib/has_contact_number/version.rb
|
108
|
+
homepage: https://github.com/AquisTech/has_contact_number
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.5.1
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Phone, mobile, fax numbers with ISD code storage and validation.
|
132
|
+
test_files: []
|