2015-10-02 21:19:00 +02:00
|
|
|
class Supporter
|
|
|
|
|
include Mongoid::Document
|
2015-10-05 14:48:54 +02:00
|
|
|
include Mongoid::Timestamps
|
2016-04-22 11:10:40 +02:00
|
|
|
include Mongoid::Paranoia
|
2015-10-06 13:07:01 +02:00
|
|
|
include Geocoder::Model::Mongoid
|
|
|
|
|
|
2016-11-15 10:05:53 +01:00
|
|
|
COUNTER_START = 10_003
|
2015-10-19 08:25:26 +02:00
|
|
|
|
2015-10-06 13:07:01 +02:00
|
|
|
geocoded_by :address
|
|
|
|
|
after_validation :geocode # auto-fetch coordinates
|
2015-10-02 21:34:31 +02:00
|
|
|
|
2016-03-29 22:08:52 +02:00
|
|
|
field :first_name, type: String
|
|
|
|
|
field :last_name, type: String
|
|
|
|
|
field :street, type: String
|
|
|
|
|
field :zip, type: Integer
|
|
|
|
|
field :city, type: String
|
|
|
|
|
field :email, type: String
|
|
|
|
|
field :support, type: String # Indicates the type of support
|
2016-03-29 22:03:06 +02:00
|
|
|
field :li_membership, type: Boolean, default: false
|
2016-03-29 22:08:52 +02:00
|
|
|
field :age_category, type: String
|
|
|
|
|
field :coordinates, type: Array
|
|
|
|
|
field :comments, type: String
|
|
|
|
|
field :language, type: String
|
2016-05-14 11:14:47 +02:00
|
|
|
field :unsubscribed, type: Boolean, default: false
|
2016-04-22 11:10:40 +02:00
|
|
|
field :duplicate, type: Boolean, default: false
|
2015-10-02 21:34:31 +02:00
|
|
|
|
2015-10-06 09:30:35 +02:00
|
|
|
validates :first_name, presence: true
|
|
|
|
|
validates :last_name, presence: true
|
|
|
|
|
validates :street, presence: true
|
|
|
|
|
validates :zip, presence: true
|
|
|
|
|
validates :city, presence: true
|
2015-10-07 14:27:50 +02:00
|
|
|
validates :email, presence: true, uniqueness: true, format: /.+@.+\..+/i
|
2015-10-03 06:38:11 +02:00
|
|
|
validates :support, presence: true
|
|
|
|
|
validates :age_category, presence: true
|
2015-11-09 10:33:26 +01:00
|
|
|
validates :language, presence: true
|
2015-10-06 13:07:01 +02:00
|
|
|
|
2015-10-19 08:25:26 +02:00
|
|
|
def self.counter
|
|
|
|
|
actual = count.to_i
|
|
|
|
|
actual > COUNTER_START ? actual : COUNTER_START
|
|
|
|
|
end
|
|
|
|
|
|
2015-10-06 13:07:01 +02:00
|
|
|
def address
|
|
|
|
|
"#{street}, #{zip}, #{city}, Switzerland"
|
|
|
|
|
end
|
2015-10-02 21:19:00 +02:00
|
|
|
end
|