has_phone_numbers 0.2.0 → 0.2.1
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.
- data/CHANGELOG.rdoc +5 -0
- data/LICENSE +1 -1
- data/README.rdoc +33 -10
- data/Rakefile +19 -17
- data/app/models/phone_number.rb +4 -4
- data/generators/has_phone_numbers/USAGE +5 -0
- data/generators/has_phone_numbers/has_phone_numbers_generator.rb +7 -0
- data/{db/migrate → generators/has_phone_numbers/templates}/001_create_phone_numbers.rb +0 -0
- data/test/app_root/db/migrate/002_migrate_has_phone_numbers_to_version_1.rb +2 -2
- metadata +16 -21
data/CHANGELOG.rdoc
CHANGED
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -23,23 +23,46 @@ Source
|
|
23
23
|
== Description
|
24
24
|
|
25
25
|
A phone number is a simple model whose data and functionality should be
|
26
|
-
standardized across multiple applications. Phone numbers are
|
27
|
-
terms of the type of data
|
28
|
-
|
26
|
+
standardized across multiple applications. Phone numbers are minimalistic in
|
27
|
+
terms of the type of data it represents. Both U.S. and international formats
|
28
|
+
are supported.
|
29
29
|
|
30
30
|
== Usage
|
31
31
|
|
32
|
-
Note that this is a reference implementation and, most likely,
|
32
|
+
Note that this is a reference implementation and, most likely, will be
|
33
33
|
modified for your own usage.
|
34
34
|
|
35
|
+
=== Installation
|
36
|
+
|
37
|
+
+has_phone_numbers+ requires an additional database table to work. You can
|
38
|
+
generate a migration for this tables like so:
|
39
|
+
|
40
|
+
script/generate has_phone_numbers
|
41
|
+
|
42
|
+
Then simply migrate your database:
|
43
|
+
|
44
|
+
rake db:migrate
|
45
|
+
|
35
46
|
=== Example
|
36
47
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
48
|
+
Building with individual segments:
|
49
|
+
|
50
|
+
PhoneNumber.create(:phoneable => user, :country_code => '1', :number => '1234567890', :extension => '123')
|
51
|
+
# #<PhoneNumber id: 1, phoneable_id: 1, phoneable_type: "User", country_code: "1", number: "1234567890", extension: "123", created_at: "2009-01-01 00:00:00", updated_at: "2009-01-01 00:00:00">
|
52
|
+
|
53
|
+
Parsing raw values:
|
54
|
+
|
55
|
+
PhoneNumber.create(:phoneable => user, :content => '1 1234567890 ext. 123')
|
56
|
+
# #<PhoneNumber id: 1, phoneable_id: 1, phoneable_type: "User", country_code: "1", number: "1234567890", extension: "123", created_at: "2009-01-01 00:00:00", updated_at: "2009-01-01 00:00:00">
|
57
|
+
|
58
|
+
PhoneNumber.create(:phoneable => user, :content => '231 331 996 x4621')
|
59
|
+
# #<PhoneNumber id: 1, phoneable_id: 1, phoneable_type: "User", country_code: "231", number: "331996", extension: "4621", created_at: "2009-01-01 00:00:00", updated_at: "2009-01-01 00:00:00">
|
60
|
+
|
61
|
+
PhoneNumber.create(:phoneable => user, :content => '+ 386 1 5853 449')
|
62
|
+
# #<PhoneNumber id: 1, phoneable_id: 1, phoneable_type: "User", country_code: "386", number: "15853449", extension: nil, created_at: "2009-01-01 00:00:00", updated_at: "2009-01-01 00:00:00">
|
63
|
+
|
64
|
+
PhoneNumber.create(:phoneable => user, :content => '+39-02-4823001')
|
65
|
+
# #<PhoneNumber id: 1, phoneable_id: 1, phoneable_type: "User", country_code: "39", number: "024823001", extension: nil, created_at: "2009-01-01 00:00:00", updated_at: "2009-01-01 00:00:00">
|
43
66
|
|
44
67
|
== Testing
|
45
68
|
|
data/Rakefile
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
1
3
|
require 'rake/testtask'
|
2
4
|
require 'rake/rdoctask'
|
3
5
|
require 'rake/gempackagetask'
|
4
|
-
require 'rake/contrib/sshpublisher'
|
5
6
|
|
6
7
|
spec = Gem::Specification.new do |s|
|
7
8
|
s.name = 'has_phone_numbers'
|
8
|
-
s.version = '0.2.
|
9
|
+
s.version = '0.2.1'
|
9
10
|
s.platform = Gem::Platform::RUBY
|
10
|
-
s.summary = 'Demonstrates a reference implementation for handling phone numbers
|
11
|
+
s.summary = 'Demonstrates a reference implementation for handling phone numbers in ActiveRecord'
|
12
|
+
s.description = s.summary
|
11
13
|
|
12
|
-
s.files = FileList['{app,
|
14
|
+
s.files = FileList['{app,generators,lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
|
13
15
|
s.require_path = 'lib'
|
14
16
|
s.has_rdoc = true
|
15
17
|
s.test_files = Dir['test/**/*_test.rb']
|
@@ -52,20 +54,27 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
52
54
|
rdoc.options << '--line-numbers' << '--inline-source'
|
53
55
|
rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG.rdoc', 'LICENSE', 'lib/**/*.rb', 'app/**/*.rb')
|
54
56
|
end
|
55
|
-
|
57
|
+
|
58
|
+
desc 'Generate a gemspec file.'
|
59
|
+
task :gemspec do
|
60
|
+
File.open("#{spec.name}.gemspec", 'w') do |f|
|
61
|
+
f.write spec.to_ruby
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
56
65
|
Rake::GemPackageTask.new(spec) do |p|
|
57
66
|
p.gem_spec = spec
|
58
|
-
p.need_tar = true
|
59
|
-
p.need_zip = true
|
60
67
|
end
|
61
68
|
|
62
69
|
desc 'Publish the beta gem.'
|
63
70
|
task :pgem => [:package] do
|
71
|
+
require 'rake/contrib/sshpublisher'
|
64
72
|
Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{spec.name}-#{spec.version}.gem").upload
|
65
73
|
end
|
66
74
|
|
67
75
|
desc 'Publish the API documentation.'
|
68
76
|
task :pdoc => [:rdoc] do
|
77
|
+
require 'rake/contrib/sshpublisher'
|
69
78
|
Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{spec.name}", 'rdoc').upload
|
70
79
|
end
|
71
80
|
|
@@ -74,15 +83,8 @@ task :publish => [:pgem, :pdoc, :release]
|
|
74
83
|
|
75
84
|
desc 'Publish the release files to RubyForge.'
|
76
85
|
task :release => [:gem, :package] do
|
77
|
-
require '
|
78
|
-
|
79
|
-
ruby_forge = RubyForge.new.configure
|
80
|
-
ruby_forge.login
|
86
|
+
require 'rake/gemcutter'
|
81
87
|
|
82
|
-
|
83
|
-
|
84
|
-
puts "Releasing #{File.basename(file)}..."
|
85
|
-
|
86
|
-
ruby_forge.add_release(spec.rubyforge_project, spec.name, spec.version, file)
|
87
|
-
end
|
88
|
+
Rake::Gemcutter::Tasks.new(spec)
|
89
|
+
Rake::Task['gem:push'].invoke
|
88
90
|
end
|
data/app/models/phone_number.rb
CHANGED
@@ -81,12 +81,12 @@ class PhoneNumber < ActiveRecord::Base
|
|
81
81
|
|
82
82
|
# The raw, unparsed content containing the phone number. This can be parsed
|
83
83
|
# in various formats, such as:
|
84
|
-
# *
|
84
|
+
# * 599 600 11 22
|
85
85
|
# * + 386 1 5853 449
|
86
|
-
# * +48 (22)
|
86
|
+
# * +48 (22) 641 0001
|
87
87
|
# * 36 1 267-4636
|
88
|
-
# * +39-02-
|
89
|
-
# *
|
88
|
+
# * +39-02-4823001
|
89
|
+
# * 231 331 996 x4621
|
90
90
|
# * 358 2 141 540 65 ext. 1423
|
91
91
|
attr_accessor :content
|
92
92
|
before_validation_on_create :parse_content, :if => :content
|
File without changes
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class MigrateHasPhoneNumbersToVersion1 < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../
|
3
|
+
ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../generators/has_phone_numbers/templates", 0).migrations.each do |migration|
|
4
4
|
migration.migrate(:up)
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
ActiveRecord::Migrator.new(:
|
9
|
+
ActiveRecord::Migrator.new(:down, "#{Rails.root}/../../generators/has_phone_numbers/templates", 0).migrations.each do |migration|
|
10
10
|
migration.migrate(:down)
|
11
11
|
end
|
12
12
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_phone_numbers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-03-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: Demonstrates a reference implementation for handling phone numbers in ActiveRecord
|
17
17
|
email: aaron@pluginaweek.org
|
18
18
|
executables: []
|
19
19
|
|
@@ -22,25 +22,18 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
-
- app/models
|
26
25
|
- app/models/phone_number.rb
|
27
|
-
-
|
28
|
-
-
|
26
|
+
- generators/has_phone_numbers/USAGE
|
27
|
+
- generators/has_phone_numbers/has_phone_numbers_generator.rb
|
28
|
+
- generators/has_phone_numbers/templates/001_create_phone_numbers.rb
|
29
29
|
- lib/has_phone_numbers.rb
|
30
|
-
- test/factory.rb
|
31
|
-
- test/test_helper.rb
|
32
|
-
- test/functional
|
33
|
-
- test/functional/has_phone_numbers_test.rb
|
34
|
-
- test/unit
|
35
30
|
- test/unit/phone_number_test.rb
|
36
|
-
- test/app_root
|
37
|
-
- test/app_root/db
|
38
|
-
- test/app_root/db/migrate
|
39
|
-
- test/app_root/db/migrate/002_migrate_has_phone_numbers_to_version_1.rb
|
40
31
|
- test/app_root/db/migrate/001_create_people.rb
|
41
|
-
- test/app_root/
|
42
|
-
- test/app_root/app/models
|
32
|
+
- test/app_root/db/migrate/002_migrate_has_phone_numbers_to_version_1.rb
|
43
33
|
- test/app_root/app/models/person.rb
|
34
|
+
- test/test_helper.rb
|
35
|
+
- test/factory.rb
|
36
|
+
- test/functional/has_phone_numbers_test.rb
|
44
37
|
- CHANGELOG.rdoc
|
45
38
|
- init.rb
|
46
39
|
- LICENSE
|
@@ -48,6 +41,8 @@ files:
|
|
48
41
|
- README.rdoc
|
49
42
|
has_rdoc: true
|
50
43
|
homepage: http://www.pluginaweek.org
|
44
|
+
licenses: []
|
45
|
+
|
51
46
|
post_install_message:
|
52
47
|
rdoc_options: []
|
53
48
|
|
@@ -68,10 +63,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
63
|
requirements: []
|
69
64
|
|
70
65
|
rubyforge_project: pluginaweek
|
71
|
-
rubygems_version: 1.3.
|
66
|
+
rubygems_version: 1.3.5
|
72
67
|
signing_key:
|
73
|
-
specification_version:
|
74
|
-
summary: Demonstrates a reference implementation for handling phone numbers
|
68
|
+
specification_version: 3
|
69
|
+
summary: Demonstrates a reference implementation for handling phone numbers in ActiveRecord
|
75
70
|
test_files:
|
76
|
-
- test/functional/has_phone_numbers_test.rb
|
77
71
|
- test/unit/phone_number_test.rb
|
72
|
+
- test/functional/has_phone_numbers_test.rb
|