Sha256: f2eebded87c99fecafa51965b2b8508e6e77caa69edc0a53fd4d47acb7017502

Contents?: true

Size: 702 Bytes

Versions: 9

Compression:

Stored size: 702 Bytes

Contents

require_relative "../../../../lib/isimud"

class Company < ActiveRecord::Base
  include Isimud::EventObserver

  has_many :users

  def self.find_active_observers
    where(active: true).all
  end

  def enable_listener?
    active
  end

  def observed_exchange
    'isimud.test.events'
  end

  def routing_keys
    ["*.User.create", "*.User.destroy"]
  end

  def handle_event(event)
    user = User.find(event.parameters[:id])
    return unless user.company_id == id
    raise "unexpected action: #{event.action}" unless ['create','destroy' ].include?(event.action.to_s)
    self.user_count = User.where(company: self).count
    self.total_points = user_count * points_per_user
    save!
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
isimud-1.4.6 spec/internal/app/models/company.rb
isimud-1.4.5 spec/internal/app/models/company.rb
isimud-1.4.4 spec/internal/app/models/company.rb
isimud-1.4.3 spec/internal/app/models/company.rb
isimud-1.3.9 spec/internal/app/models/company.rb
isimud-1.4.2 spec/internal/app/models/company.rb
isimud-1.4.1 spec/internal/app/models/company.rb
isimud-1.3.8 spec/internal/app/models/company.rb
isimud-1.3.1 spec/internal/app/models/company.rb