Class: ActiveRecord::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/pluck_all.rb,
lib/pluck_all.rb

Instance Method Summary collapse

Instance Method Details

#cast_need_columns(column_names, _klass = nil) ⇒ Object



49
50
51
52
53
# File 'lib/pluck_all.rb', line 49

def cast_need_columns(column_names, _klass = nil)
  @pluck_all_cast_need_columns = column_names.map(&:to_s)
  @pluck_all_cast_klass = _klass
  return self
end

#pluck_all(*args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/pluck_all.rb', line 27

def pluck_all(*args)
  result = select_all(*args)
  result.map! do |attributes| #This map! behaves different to array#map!
    initialized_attributes = klass.initialize_attributes(attributes)
    attributes.each do |key, attribute|
      attributes[key] = klass.type_cast_attribute(key, initialized_attributes) #TODO 現在AS過後的type cast會有一點問題
    end
    cast_carrier_wave_uploader_url(attributes)
  end
end