Module: DataMapper::Address::US::ClassMethods

Defined in:
lib/dm-address/us.rb

Overview

class << self

Instance Method Summary collapse

Instance Method Details

#address_properties(options = {}) ⇒ Object

Setup properties. Already added properties are not overriden. options:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dm-address/us.rb', line 22

def address_properties(options = {})
  reqs = options[:required_fields] || 
         DataMapper::Address.config[:us_required_fields] || 
         DEFAULT_REQUIRED_FIELDS
  
  [
    [:id, DataMapper::Property::Serial],
    [:name, String, {:length => 100}],
    [:company, String, {:length => 100}],
    [:street, String, {:length => 100}],
    [:street_2, String],
    [:city, String, {:length => 100}],
    [:state, String, {:length => 2}],
    [:postal_code, DataMapper::Property::ZipCode, {:format => :zip_code}],
    [:country, String, {:required => false, :length => 50, :default => 'USA'}],
    [:phone, DataMapper::Property::PhoneNumber, {:format => :phone_number}],
    [:created_at, DateTime],
    [:updated_at, DateTime]
  ].each do |args|
    unless self.properties.named?(args[0])
      args[0] = "#{options[:prefix]}#{args[0]}" if options[:prefix]
      args[2] ||= {}
      args[2][:required] = reqs.include?(args[0])
      self.property(*args)
    end
  end
  
  if options[:polymorphic]
    include(DataMapper::Address::Polymorphic)
  end
end