public
Description: open-source e-commerce built on merb
Clone URL: git://github.com/myabc/merb_mart.git
Search Repo:
Click here to lend your support to: merb_mart and make a donation at www.pledgie.com !
myabc (author)
Thu May 08 03:15:21 -0700 2008
commit  72213a301782666f2277ba78d342274676328233
tree    814b722a9527d1e15ccc4313fcfb168e5081bbb6
parent  8388fe58541d56708c0b85fcc0e940d7946c9179
merb_mart / app / models / address.rb
100644 41 lines (33 sloc) 1.188 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#
# A generic representation of an Address.
#
class Address
 
  include DataMapper::Resource
  include DataMapper::Validate
 
  property :first_name, String, :length => 50, :nullable => false
  property :last_name, String, :length => 50, :nullable => false
  property :company, String, :length => 100
  property :telephone, String, :length => 20
  property :address1, String, :length => 200, :nullable => false
  property :address2, String, :length => 200
  property :city, String, :length => 50
  property :postal_code, String, :length => 10
  property :state_id, Fixnum # foreign-key
  property :country_code, String # foreign-key
 
  belongs_to :state
  belongs_to :country
 
  validates_presence_of :first_name
  validates_presence_of :last_name
  validates_presence_of :address1
  validates_presence_of :postal_code
 
  validates_length_of :first_name, :maximum => 50
  validates_length_of :last_name, :maximum => 50
  validates_length_of :address1, :maximum => 255
 
  alias :zipcode :postal_code
  alias :zipcode= :postal_code=
  alias :province :state
  alias :province= :state=
 
  def name
    "#{self.first_name} #{self.last_name}"
  end
 
end