Sha256: 2e03f6637fb1d602fdc92205d9b4d9857f044f9212b73ee746f1962f569621f6

Contents?: true

Size: 685 Bytes

Versions: 4

Compression:

Stored size: 685 Bytes

Contents

require 'deep_pluck/version'
require 'deep_pluck/model'
require 'active_record'
require 'pluck_all'

class ActiveRecord::Relation
  def deep_pluck(*args)
    DeepPluck::Model.new(self).add(args).load_all
  end
end

class ActiveRecord::Base
  def self.deep_pluck(*args)
    where('').deep_pluck(*args)
  end

  def self.visible_for(*)
    all
  end

  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deep_pluck_with_authorization-1.1.5 lib/deep_pluck.rb
deep_pluck_with_authorization-1.1.4 lib/deep_pluck.rb
deep_pluck_with_authorization-1.1.3 lib/deep_pluck.rb
deep_pluck_with_authorization-1.1.2 lib/deep_pluck.rb