Class: ActiveRecord::Base

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.deep_pluck(*args) ⇒ Object



15
16
17
# File 'lib/deep_pluck.rb', line 15

def self.deep_pluck(*args)
  where('').deep_pluck(*args)
end

Instance Method Details

#deep_pluck(*args) ⇒ Object



19
20
21
22
23
24
# File 'lib/deep_pluck.rb', line 19

def deep_pluck(*args)
  hash_args, other_args = args.partition{|s| s.is_a?(Hash) }
  model = DeepPluck::Model.new(self, need_columns: other_args)
  model.add(*hash_args) if hash_args.any?
  return model.load_all.first
end