Sha256: 819eaf288e74a7379bd2c63890845fce5c5615956ffdb35c79d24e174949156b

Contents?: true

Size: 569 Bytes

Versions: 7

Compression:

Stored size: 569 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 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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
deep_pluck-1.2.1 lib/deep_pluck.rb
deep_pluck-1.2.0 lib/deep_pluck.rb
deep_pluck-1.1.7 lib/deep_pluck.rb
deep_pluck-1.1.6 lib/deep_pluck.rb
deep_pluck-1.1.5 lib/deep_pluck.rb
deep_pluck-1.1.4 lib/deep_pluck.rb
deep_pluck-1.1.3 lib/deep_pluck.rb