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



13
14
15
# File 'lib/deep_pluck.rb', line 13

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

.visible_forObject



17
18
19
# File 'lib/deep_pluck.rb', line 17

def self.visible_for(*)
  all
end

Instance Method Details

#deep_pluck(*args) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/deep_pluck.rb', line 21

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