Sha256: 143fd1180715baab6cc39f46072fec9c2811b950c4ed239c8a46bb39b2901a81

Contents?: true

Size: 807 Bytes

Versions: 5

Compression:

Stored size: 807 Bytes

Contents

class Client < Prometeus
  extend Enumerize
  extend ActiveModel::Naming

  belongs_to :country
  belongs_to :city

  enumerize :sex, in: %w[male female other], i18n_scope: 'sex'

  scope :males, -> {where(sex: 'male')}
  scope :females, -> {where(sex: 'female')}
  scope :others, -> {where(sex: 'other')}
  scope :birthdays, -> {where('DATE_FORMAT(birthday, "%m%d")=?', DateTime.now.strftime('%m%d'))}

  after_update :check_country

  def happy_birthday?
    require 'happy_birthday'
    self.birthday.happy_birthday?
  end

  # назначение страны если первым выбирается город
  def check_country
    if saved_change_to_attribute?(:city_id)
      unless self.city.nil?
        self.update(country: self.city.country) unless self.country
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
digital_heroes_startkit-0.1.1.4 app/models/client.rb
digital_heroes_startkit-0.1.1.3 app/models/client.rb
digital_heroes_startkit-0.1.1.2 app/models/client.rb
digital_heroes_startkit-0.1.1.1 app/models/client.rb
digital_heroes_startkit-0.1.1 app/models/client.rb