Sha256: e8090769d8ff05e0fb31d43dc4c391db2d3d2ca07563fbe5607f28dedf4e938a

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

class TerminalProfile < ActiveRecord::Base
  include Redis::Objects::RMap

  has_rmap({:id => lambda{|x| x.to_s}}, :keyword)
  has_paper_trail

  has_many :terminals, :conditions => "terminal_profile_id IS NOT NULL"
  has_many :terminal_profile_promotions, :dependent => :destroy, :order => :priority
  has_many :terminal_profile_providers, :dependent => :destroy, :order => :priority
  has_many :terminal_profile_provider_groups, :dependent => :destroy, :order => :priority

  mount_uploader :logo, FileUploader

  accepts_nested_attributes_for :terminal_profile_promotions, :allow_destroy => true
  accepts_nested_attributes_for :terminal_profile_providers
  accepts_nested_attributes_for :terminal_profile_provider_groups

  def actualize_links!
    group_ids = [-1] + terminal_profile_provider_groups.map{|x| x.provider_group_id}
    prov_ids  = [-1] + terminal_profile_providers.map{|x| x.provider_id}

    ProviderGroup.where(ProviderGroup.arel_table[:id].not_in group_ids).each do |pg|
      terminal_profile_provider_groups << TerminalProfileProviderGroup.new(:provider_group_id => pg.id, :terminal_profile_id => id)
    end

    Provider.where(Provider.arel_table[:id].not_in prov_ids).each do |p|
      terminal_profile_providers << TerminalProfileProvider.new(:provider_id => p.id, :terminal_profile_id => id)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smartkiosk-server-0.9.1 app/models/terminal_profile.rb