validates_numericality_of :user_id, :integer_only => true
validates_numericality_of :num_changes, :integer_only => true, :greater_than_or_equal_to => 0
+ before_save :update_closed_at
+
# over-expansion factor to use when updating the bounding box
EXPAND = 0.1
# set the auto-close time to be one hour in the future unless
# that would make it more than 24h long, in which case clip to
# 24h, as this has been decided is a reasonable time limit.
- def before_save
+ def update_closed_at
if self.is_open?
if (closed_at - created_at) > (MAX_TIME_OPEN - IDLE_TIMEOUT)
self.closed_at = created_at + MAX_TIME_OPEN
set_table_name 'current_relation_members'
set_primary_keys :id, :sequence_id
+
belongs_to :member, :polymorphic => true
belongs_to :relation, :foreign_key => :id
- def after_find
- self[:member_class] = self.member_type.classify
+ after_find :set_class_from_type
+ after_initialize :set_class_from_type
+ before_save :set_type_from_class
+
+ def member_type=(type)
+ self[:member_type] = type
+ self[:member_class] = type.capitalize
end
- def after_initialize
+private
+
+ def set_class_from_type
self[:member_class] = self.member_type.classify unless self.member_type.nil?
end
- def before_save
+ def set_type_from_class
self.member_type = self[:member_class].classify
end
-
- def member_type=(type)
- self[:member_type] = type
- self[:member_class] = type.capitalize
- end
end
validates_numericality_of :home_zoom, :only_integer => true, :allow_nil => true
validates_inclusion_of :preferred_editor, :in => Editors::ALL_EDITORS, :allow_nil => true
+ after_initialize :set_creation_time
before_save :encrypt_password
file_column :image, :magick => { :geometry => "100x100>" }
- def after_initialize
- self.creation_time = Time.now.getutc unless self.attribute_present?(:creation_time)
- end
-
- def encrypt_password
- if pass_crypt_confirmation
- self.pass_salt = OSM::make_token(8)
- self.pass_crypt = OSM::encrypt_password(pass_crypt, pass_salt)
- end
- end
-
def self.authenticate(options)
if options[:username] and options[:password]
user = find(:first, :conditions => ["email = ? OR display_name = ?", options[:username], options[:username]])
def access_token(application_key)
return ClientApplication.find_by_key(application_key).access_token_for_user(self)
end
+
+private
+
+ def set_creation_time
+ self.creation_time = Time.now.getutc unless self.attribute_present?(:creation_time)
+ end
+
+ def encrypt_password
+ if pass_crypt_confirmation
+ self.pass_salt = OSM::make_token(8)
+ self.pass_crypt = OSM::encrypt_password(pass_crypt, pass_salt)
+ end
+ end
end
class UserToken < ActiveRecord::Base
belongs_to :user
- def after_initialize
+ after_initialize :set_defaults
+
+private
+
+ def set_defaults
self.token = OSM::make_token() if self.token.blank?
self.expiry = 1.week.from_now if self.expiry.blank?
end
def self.included(base)
base.extend(ClassMethods)
- end
-
- def before_save
- self.update_tile
+ base.before_save :update_tile
end
# Is this node within -90 >= latitude >= 90 and -180 >= longitude >= 180