Sha256: d28bfa446aca7ae55423beec9d93f4e260ba991b3fd8f9cea84d0617463d01b0

Contents?: true

Size: 518 Bytes

Versions: 5

Compression:

Stored size: 518 Bytes

Contents

# frozen_string_literal: true

require 'rails_compatibility/active_record'

class << RailsCompatibility
  if GTE_RAILS_6_0
    def pick(relation, *args)
      relation.pick(*args)
    end
  elsif GTE_RAILS_4_0
    def pick(relation, *args)
      relation.limit(1).pluck(*args).first
    end
  else
    def pick(relation, *args)
      model = relation.first

      return nil if model == nil
      return model[args.first] if args.size == 1
      return args.map{|s| model[s] }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_compatibility-0.0.10 lib/rails_compatibility/pick.rb
rails_compatibility-0.0.9 lib/rails_compatibility/pick.rb
rails_compatibility-0.0.8 lib/rails_compatibility/pick.rb
rails_compatibility-0.0.7 lib/rails_compatibility/pick.rb
rails_compatibility-0.0.6 lib/rails_compatibility/pick.rb