Sha256: 8156cad0b46d4c0751ae1c7ea8806d8372ee968f0f8869c30c28658e49764b91

Contents?: true

Size: 975 Bytes

Versions: 1

Compression:

Stored size: 975 Bytes

Contents

require 'deep_pluck/version'
require 'deep_pluck/config'
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

  def ta_pluck(*attribute_names)
    args = DeepPluck::Config.attribute_names_to_args(attribute_names)
    deep_pluck(*args)
  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

  def self.ta_pluck(*attribute_names)
    args = DeepPluck::Config.attribute_names_to_args(attribute_names)
    deep_pluck(*args)
  end

  def ta_pluck(*attribute_names)
    args = DeepPluck::Config.attribute_names_to_args(attribute_names)
    deep_pluck(*args)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ta_deep_pluck-1.3.0 lib/deep_pluck.rb