Module: ActiveRecordExtension::ClassMethods

Defined in:
lib/active_record_extension.rb

Overview

add your static(class) methods here

Instance Method Summary collapse

Instance Method Details

#grab(which, what, options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_record_extension.rb', line 12

def grab(which,what,options)
  pluck=Assist.make_string_list(what)
  unless options[:swap].nil?
    swaps=options[:swap]
    swaps.each_key { |key|
      index=what.index(key.to_sym)
      what[index]=swaps[key.to_sym]
    }
  end
  order=Assist.make_string_list(options[:sort]) unless options.nil? || options[:sort].nil?
  if which=='all'
    order.nil?  ?
        Assist.named_array(self.all.pluck(pluck),what) :
        Assist.named_array(self.all.order(order).pluck(pluck),what)
  else
    order.nil? ?
        Assist.named_array(self.where(which).pluck(pluck),what) :
        Assist.named_array(self.where(which).order(order).pluck(pluck),what)
  end
end