jm81-dm-address 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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/dm-address.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{dm-address}
5
- s.version = "0.1.1"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jared Morgan"]
9
- s.date = %q{2009-07-18}
9
+ s.date = %q{2009-07-22}
10
10
  s.email = %q{jmorgan@morgancreative.net}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -26,6 +26,8 @@ Gem::Specification.new do |s|
26
26
  "lib/dm-address/zip_code.rb",
27
27
  "lib/dm-types/phone_number.rb",
28
28
  "lib/dm-types/zip_code.rb",
29
+ "lib/dm-validations/formats/phone_number.rb",
30
+ "lib/dm-validations/formats/zip_code.rb",
29
31
  "spec/dm-address/phone_number_spec.rb",
30
32
  "spec/dm-address/us_spec.rb",
31
33
  "spec/dm-address/zip_code_spec.rb",
data/lib/dm-address.rb CHANGED
@@ -35,3 +35,7 @@ end
35
35
  require File.dirname(__FILE__) + '/dm-types/' + file
36
36
  end
37
37
 
38
+ # Require dm-validations/formats files
39
+ %w{ phone_number zip_code }.each do |file|
40
+ require File.dirname(__FILE__) + '/dm-validations/formats/' + file
41
+ end
data/lib/dm-address/us.rb CHANGED
@@ -32,13 +32,9 @@ module DataMapper
32
32
  [:street_2, String],
33
33
  [:city, String, {:length => 100}],
34
34
  [:state, String, {:length => 2}],
35
- [:postal_code, DataMapper::Types::ZipCode, {
36
- :format => Proc.new { |zc| zc.blank? || zc.length == 5 || zc.length == 9 },
37
- :messages => { :format => "Postal code should be 5 digits or 9 digits (ZIP+4)" }}],
35
+ [:postal_code, DataMapper::Types::ZipCode, {:format => :zip_code}],
38
36
  [:country, String, {:nullable => false, :length => 50, :default => 'USA'}],
39
- [:phone, DataMapper::Types::PhoneNumber, {
40
- :format => Proc.new { |ph| ph.blank? || ph.length == 10 },
41
- :messages => { :format => "Phone number should be 10 digits (include area code)" }}],
37
+ [:phone, DataMapper::Types::PhoneNumber, {:format => :phone_number}],
42
38
  [:created_at, DateTime],
43
39
  [:updated_at, DateTime]
44
40
  ].each do |args|
@@ -1,7 +1,7 @@
1
1
  module DataMapper
2
2
  module Address
3
3
  class ZipCode < String
4
- # Remove all non-digits from given phone number
4
+ # Remove all non-digits from given zip code
5
5
  def initialize(s)
6
6
  super((s || '').gsub(/\D+/, ''))
7
7
  end
@@ -0,0 +1,19 @@
1
+ module DataMapper
2
+ module Validate
3
+ module Format
4
+ module PhoneNumber
5
+
6
+ def self.included(base)
7
+ DataMapper::Validate::FormatValidator::FORMATS.merge!(
8
+ :phone_number => [
9
+ Proc.new { |ph| ph.blank? || ph.length == 10 },
10
+ lambda { |field, value| '%s should be 10 digits (include area code)'.t(value) }
11
+ ]
12
+ )
13
+ end
14
+ end # module PhoneNumber
15
+ end # module Format
16
+ end # module Validate
17
+ end # module DataMapper
18
+
19
+ DataMapper::Validate::FormatValidator.__send__(:include, DataMapper::Validate::Format::PhoneNumber)
@@ -0,0 +1,19 @@
1
+ module DataMapper
2
+ module Validate
3
+ module Format
4
+ module ZipCode
5
+
6
+ def self.included(base)
7
+ DataMapper::Validate::FormatValidator::FORMATS.merge!(
8
+ :zip_code => [
9
+ Proc.new { |zc| zc.blank? || zc.length == 5 || zc.length == 9 },
10
+ lambda { |field, value| '%s should be 5 digits or 9 digits (ZIP+4)'.t(value) }
11
+ ]
12
+ )
13
+ end
14
+ end # module ZipCode
15
+ end # module Format
16
+ end # module Validate
17
+ end # module DataMapper
18
+
19
+ DataMapper::Validate::FormatValidator.__send__(:include, DataMapper::Validate::Format::ZipCode)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jm81-dm-address
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
  - Jared Morgan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-18 00:00:00 -07:00
12
+ date: 2009-07-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -75,6 +75,8 @@ files:
75
75
  - lib/dm-address/zip_code.rb
76
76
  - lib/dm-types/phone_number.rb
77
77
  - lib/dm-types/zip_code.rb
78
+ - lib/dm-validations/formats/phone_number.rb
79
+ - lib/dm-validations/formats/zip_code.rb
78
80
  - spec/dm-address/phone_number_spec.rb
79
81
  - spec/dm-address/us_spec.rb
80
82
  - spec/dm-address/zip_code_spec.rb