Sha256: 1539372609e3446e696e22357f8baef039277d943c392cd30a5ef17dcea4a7cd

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

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

  value :timestamp, :global => true, :marshal => true

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

  mount_uploader :icon, IconUploader

  after_save do
    self.class.timestamp = updated_at
  end

  after_destroy do
    self.class.timestamp = DateTime.now
  end

  #
  # RELATIONS
  #
  belongs_to :provider_profile
  belongs_to :provider_group
  belongs_to :provider_receipt_template
  has_many   :provider_gateways
  has_many   :gateways, :through => :provider_gateways
  has_many   :payments, :order => 'id DESC'
  has_many   :commissions, :through => :provider_profile
  has_many   :limits, :through => :provider_profile
  has_many   :provider_fields, :dependent => :destroy, :order => :priority
  has_many   :terminal_profile_providers, :dependent => :destroy, :order => :priority
  has_many   :terminal_profile_promotions, :dependent => :destroy, :order => :priority

  accepts_nested_attributes_for :provider_gateways, :allow_destroy => true
  accepts_nested_attributes_for :provider_fields, :allow_destroy => true

  scope :gateway_ids_eq, lambda{|x| includes(:gateways).where(:gateways => {:id => x})}
  search_method :gateway_ids_eq

  scope :after, lambda{|x| 
    x.blank? ? scoped 
             : where(arel_table[:updated_at].gt x)
  }

  #
  # VALIDATIONS
  #
  validates :provider_profile, :presence => true
  validates :provider_group, :presence => true
  validates :keyword, :presence => true
  validates :keyword, :uniqueness => true

  #
  # METHODS
  #
  def fields_dump
    provider_fields.as_json(:only => [:keyword, :title, :kind, :mask, :values, :priority])
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
smartkiosk-server-0.9.3 app/models/provider.rb
smartkiosk-server-0.9.2 app/models/provider.rb
smartkiosk-server-0.9.1 app/models/provider.rb
smartkiosk-server-0.9.0 app/models/provider.rb