Sha256: 0638376d8e55bd2ecef5cfbe6ae59b5376c58834b7f71017dd5409bd7ef942f8

Contents?: true

Size: 911 Bytes

Versions: 44

Compression:

Stored size: 911 Bytes

Contents

require 'carrierwave/orm/activerecord'

class Provider < ActiveRecord::Base
  belongs_to :group
  serialize :fields

  mount_uploader :icon, IconUploader

  scope :active, where(arel_table[:fields_count].gt 0)

  before_save do
    self.fields_count = fields.length
  end

  after_save do
    Terminal.modified_at = DateTime.now
  end

  after_destroy do
    Terminal.modified_at = DateTime.now
  end

  def as_json
    {
      :id => id,
      :group => group_id,
      :keyword => keyword,
      :title => title,
      :icon => icon.url,
      :fields => fields
    }
  end

  def self.to_hash(column, entries=false, options={})
    scope = Provider.select([:id, column])
    scope = scope.where(column => entries) if entries
    scope = scope.map{|x| [x.id, x.send(column)]} if options[:invert].blank?
    scope = scope.map{|x| [x.send(column), x.id]} if options[:invert]

    Hash[*scope.flatten]
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
smartkiosk-client-0.2.1 app/models/provider.rb
smartkiosk-client-0.2 app/models/provider.rb
smartkiosk-client-0.1.19 app/models/provider.rb
smartkiosk-client-0.1.18 app/models/provider.rb
smartkiosk-client-0.1.17 app/models/provider.rb
smartkiosk-client-0.1.16 app/models/provider.rb
smartkiosk-client-0.1.15 app/models/provider.rb
smartkiosk-client-0.1.14 app/models/provider.rb
smartkiosk-client-0.1.13 app/models/provider.rb
smartkiosk-client-0.1.12 app/models/provider.rb
smartkiosk-client-0.1.11 app/models/provider.rb
smartkiosk-client-0.1.10 app/models/provider.rb
smartkiosk-client-0.1.9 app/models/provider.rb
smartkiosk-client-0.1.8 app/models/provider.rb
smartkiosk-client-0.1.7 app/models/provider.rb
smartkiosk-client-0.1.6 app/models/provider.rb
smartkiosk-client-0.1.5 app/models/provider.rb
smartkiosk-client-0.1.4 app/models/provider.rb
smartkiosk-client-0.1.3 app/models/provider.rb
smartkiosk-client-0.1.2 app/models/provider.rb